问题:
Num String Score
1 Overall 5
1 Comments Good
2 Overall 4
2 Comments Fine
3 Overall 5
3 Comments Fine
我想要这样的结果。
Num String Score Comments
1 Overall 5 Good
2 Overall 4 Fine
3 Overall 5 Fine
有人可以为此提供SQL代码吗?
答案 0 :(得分:2)
这是使用conditional aggregation
的一种方法:
select num,
'Overall' as string,
max(case when string = 'Overall' then score end) as score
max(case when string = 'Comments' then score end) as comments
from yourtable
group by num