透视SQL特定列

时间:2018-01-11 12:22:14

标签: sql pivot

我坚持以下

我想将小时列中的值用作实际字符串

知道怎么做吗?

Name|Team|Area|Count|Hour
Bob |J1  |UK  |1    | 8
Jim |J1  |UK  |1    | 9
Tim |J1  |UK  |1    | 9
Tom |J1  |UK  |1    | 10

1 个答案:

答案 0 :(得分:1)

根据预期的行更改此查询。

 SELECT * 
 FROM 
 ( SELECT Name,Team,Area,Count,Hour FROM Tb_Name
 )
 PIVOT
     (COUNT(Name) FOR Hour IN ([8],[9],[10])) P