我有以下数据我正在尝试进行透视。我的目标是每个标签一行,每周变成一列,以速率作为一周的值。
这是我的查询:
SELECT * FROM table1 PIVOT ( SUM(Rate) FOR Week IN (Week0,Week1,Week2,Week3,Week4,Week5,Week6,Week7,Week8,Week9,Week10,Week11,Week12) ) pivot_table;
此结果始终为 NULL。我做错了什么?我正在关注几个教程但没有成功。
是的,那些括号会做。
SELECT * FROM (VALUES('51220','Week 0',-11) ,('51220','Week 1',-41) ,('51347','Week 1', 24) ) table1(Label, Week, Rate) PIVOT (SUM(rate) FOR WEEK IN ([Week 0],[Week 1])) AS pivot_table