T-SQL Pivot one column to one row - sql

I have a one-column table that can vary in size depending on the day. Let's say the table has 6,000 rows. Is there a way you can pivot this table in T-SQL so that is 6,000 columns without having to specify each column name?

Related

Select a single column across an entire database

I have database (couple hundred tables) that all contains a specific column called LastReplicationDate. This column name is always the same in each table, and is always the same value within each table.
Is it possible to write a query that gets the distinct value of this column assigned to each table in my database without having to select each table via a union query?

Maria DB how to format my sql statement to pull data from my table(s) into cells based on values in column and keywords in rows

Been a minute since I did SQL programming. I have a large table that can be broken up into several tables.
What I need is where date and keyword row, put the "integer" in the cell. So I have the different years (not sequential, like 1950, 1956, 1958, 1961 ...) going across the top, keywords defining the rows and the integer in the cells.
And what is the best way to sort the columns in date order oldest to the newest. Different quantities of dates for each report.
Thanks

Is there a query to get all the columns between 2 columns?

I have a table with >50 columns. I have the names of two columns. However, I would like to sum the values of these 2 columns as well as all the columns between them (>50). It seems very impractical to type all the column names in a sum statement. Is there a query for this? I am using SQL Impala by the way.

SQL Query to count multiple values from one table into specific view

I like to request your help. I can get the results seperated but now i want to create a query which has it perfect for a external person. my explanation:
I have a statistics database with in this database a table when some records comes in and each records has several columns with values etc...
Now one of these columns is called "MT"
MT Column can have only one of the following values per records: A,B,C,D,E
The records also have a columne called TotalAmount which indicate a size of a value outside the database. This TotalAmount column is numeric without decimals and can have a value between 1 and 10.000.
And the last part is the records it self, the table has X amount of records.
So Basicly i need to create a query which seperates each MT value and calculates the amount of records per MT and the sum of TotalAmount.
This is on SQL Server 2005.
Many thanks for your assistance!
Very hard to guess without a full db schema. But I think you need.
SELECT MT, Count(*), SUM (TotalAmout)
FROM YourTable
GROUP BY MT

String Grouping from a single column in Oracle database having million rows and removing duplicates

We have a huge table and one of the column contains queries like e.g. in row 1
1. (((firstname:Adam OR firstname:Neil ) AND lastname:Lee) ) AND category:"Legal" AND type:Individual
and in row 2 of same column
2. (((firstname:Adam* OR firstname:Neil ) AND lastname:Lee) ) AND category:"Legal" AND type:Organization
Similarly there are few other types of Query strings which are used eventually to query external services.
Issue is based on certain criteria I have to group and remove duplicates from this table.
There are few rules to determine grouping of Strings in different rows.One of them is that if first name and lastname are same then ignore category and type values, therefore above two rows will be grouped to one. There are around million rows. Comparing Strings and doing grouping is not looking elegant solution. What could be best possible solution using sql.