没有聚合函数的TSQL数据轴我有张这样的桌子.。CustomerID DBColumnName Data--------------------------------------1 FirstName Joe1 MiddleName S1 LastName Smith1 Date 12/12/20092 FirstName Sam2 MiddleName S2 LastName Freddrick2 Date 1/12/20093 FirstName Jaime3 MiddleName S3 LastName Carol3 Date 12/1/2009我想要这个.。这能用枢轴吗?CustomerID FirstName MiddleName LastName Date----------------------------------------------------------------------1 Joe S Smith 12/12/20092 Sam S Freddrick 1/12/20093 Jaime S Carol 12/1/2009
3 回答
jeck猫
TA贡献1909条经验 获得超7个赞
慕姐8265434
TA贡献1813条经验 获得超2个赞
Select CustomerID, Min(Case DBColumnName When 'FirstName' Then Data End) FirstName, Min(Case DBColumnName When 'MiddleName' Then Data End) MiddleName, Min(Case DBColumnName When 'LastName' Then Data End) LastName, Min(Case DBColumnName When 'Date' Then Data End) Date From table Group By CustomerId
慕妹3242003
TA贡献1824条经验 获得超6个赞
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;
添加回答
举报
0/150
提交
取消