TSQL Pivot without aggregate function

后端 未结 9 1762
青春惊慌失措
青春惊慌失措 2020-11-22 09:10

I have a table like this...

CustomerID   DBColumnName   Data
--------------------------------------
1            FirstName      Joe
1            MiddleName           


        
9条回答
  •  难免孤独
    2020-11-22 09:35

    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;
    

提交回复
热议问题