How to convert rows to columns using Cube, Pivot or Rollup SQL
1 answer
One way is to use conditional aggregation:
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;
Demo
Or using PIVOT
:
select *
from your_table
pivot (
max(quality) for score in ([2015],[2016],[2017])
) p;
Demo
+4
source to share