test table:
测试数据:
[table]
||id||年||月||收入||
||1||2008||2||100||
||2||2009||7||200||
||3|| 2009 ||9||300||
||4|| 2009 ||11||400||
[/table]
按年、季收入情况分组的SQL语句:
执行结果:
[table]
||2008||1||100
||2009||3||500
||2009||4||400
[/table]
create table test(
id number(2) primary key ,
year number(4),
month number(2),
income number(8)
)
测试数据:
[table]
||id||年||月||收入||
||1||2008||2||100||
||2||2009||7||200||
||3|| 2009 ||9||300||
||4|| 2009 ||11||400||
[/table]
按年、季收入情况分组的SQL语句:
select year,to_char(to_date(concat(year,month),'yyyymm'),'Q') as quater,sum(income)
from test
group by to_char(to_date(concat(year,month),'yyyymm'),'Q'),year
order by year,quater
执行结果:
[table]
||2008||1||100
||2009||3||500
||2009||4||400
[/table]