create table T_TEMP
(
year VARCHAR2(4),
season VARCHAR2(10),
count NUMBER(4)
)
insert into T_TEMP (year, season, count)
values ('2010', '一季度', 100);
insert into T_TEMP (year, season, count)
values ('2010', '二季度', 200);
insert into T_TEMP (year, season, count)
values ('2010', '三季度', 300);
insert into T_TEMP (year, season, count)
values ('2010', '四季度', 400);
insert into T_TEMP (year, season, count)
values ('2011', '一季度', 150);
insert into T_TEMP (year, season, count)
values ('2011', '二季度', 250);
insert into T_TEMP (year, season, count)
values ('2011', '三季度', 350);
insert into T_TEMP (year, season, count)
values ('2011', '四季度', 450);
要求一条sql语句得出以下格式
year | 一季度 | 二季度 | 三季度 | 四季度 |
2010 | 100 | 200 | 300 | 400 |
2011 | 150 | 250 | 350 | 450 |
sql如下:
select year,
sum(decode(season, '一季度', count)) as "一季度",
sum(decode(season, '二季度', count)) as "二季度",
sum(decode(season, '三季度', count)) as "三季度",
sum(decode(season, '四季度', count)) as "四季度"
from T_TEMP
group by year;