分类:
SQL
数据表
create table temp (
year int,
month int,
amout float
)
insert temp values(1991,1,1.1)
insert temp values(1991,2,1.2)
insert temp values(1991,3,1.3)
insert temp values(1991,4,1.4)
insert temp values(1992,1,2.1)
insert temp values(1992,2,2.2)
insert temp values(1992,3,2.3)
insert temp values(1992,4,2.4)
实现根据查询达到以下效果
select YEAR ,SUM(case when MONTH = 1 then amout else 0 end) as m1 ,SUM(case when MONTH = 2 then amout else 0 end) as m2 ,SUM(case when MONTH = 3 then amout else 0 end) as m3 ,SUM(case when MONTH = 4 then amout else 0 end) as m4 from temp group by year
评价