sql pivot without aggregate 1

sql pivot without aggregate

WITH pivot_data AS
SELECT customerid, -- Grouping Column
dbcolumnname, -- Spreading Column
data -- Aggregate Column
FROM pivot2 
SELECT customerid, [firstname], [middlename], [lastname]
FROM pivot_data
PIVOT (max(data) FOR dbcolumnname IN ([firstname],[middlename],[lastname])) AS p;

Here is what the above code is Doing:
1. The first CTE is grouping the data by customerid and dbcolumnname.
2. The second CTE is pivoting the data.
3. The final SELECT statement is selecting the customerid and the pivoted data.

Similar Posts