SQL: Case when then
View Code
SELECT b.年度 as '年份', sum(b.quarter1) as '1季度', sum(b.quarter2) as '2季度', sum(b.quarter3) as '3季度', sum(b.quarter4) as '4季度' From( select a.年度, case a.季度 when 1 then a.数量 else 0 end as quarter1, case a.季度 when 2 then a.数量 else 0 end as quarter2, case a.季度 when 3 then a.数量 else 0 end as quarter3, case a.季度 when 4 then a.数量 else 0 end as quarter4 FROM Case_Test a)b group by b.年度