用标准sql语句实现
year month total
1996 1 3000
1996 3 4000
1996 7 5000
1997 3 4000
1997 6 3000
.
.
year m1,m2,m3,m4year 为年,m1等为季度,要求按上行输出
year month total
1996 1 3000
1996 3 4000
1996 7 5000
1997 3 4000
1997 6 3000
.
.
year m1,m2,m3,m4year 为年,m1等为季度,要求按上行输出
sum(case when month between 1 and 3 then total else 0 end ) m1,
sum(case when month between 4 and 6 then total else 0 end ) m2,
sum(case when month between 7 and 9 then total else 0 end ) m3,
sum(case when month between 10 and 12 then total else 0 end ) m4
from table group by year
sum(decode(ceil(month / 3),1,total)) as m1,
sum(decode(ceil(month / 3),2,total)) as m2,
sum(decode(ceil(month / 3),3,total)) as m3,
sum(decode(ceil(month / 3),4,total)) as m4
from yourtable group by year;