我有一张包含以下信息的表格:
code score quality
123 2015 12
123 2016 16
123 2017 14
我希望展示这样的内容
code 2015 2016 2017
123 12 16 14
你能帮我一下吗?谢谢。
我有一张包含以下信息的表格:
code score quality
123 2015 12
123 2016 16
123 2017 14
我希望展示这样的内容
code 2015 2016 2017
123 12 16 14
你能帮我一下吗?谢谢。
一种方法是使用条件聚合:
select code,
max(case when score = 2015 then quality end) as [2015],
max(case when score = 2016 then quality end) as [2016],
max(case when score = 2017 then quality end) as [2017]
from your_table
group by code;
或者使用 PIVOT
:
select *
from your_table
pivot (
max(quality) for score in ([2015],[2016],[2017])
) p;