17,377
社区成员
发帖
与我相关
我的任务
分享
with t as
(select 2009 as year,1 as month,1000 as saleNumber from dual UNION ALL
select 2009, 2, 1200 from dual UNION ALL
select 2009, 3, 1100 from dual UNION ALL
select 2009, 4, 1150 from dual UNION ALL
select 2010, 1, 1300 from dual UNION ALL
select 2010, 2, 1350 from dual UNION ALL
select 2010, 3, 1250 from dual UNION ALL
select 2010, 4, 1350 from dual
)
select year,
sum(case month when 1 then saleNumber end) as m1,
sum(case month when 2 then saleNumber end) as m2,
sum(case month when 3 then saleNumber end) as m3,
sum(case month when 4 then saleNumber end) as m4
from t
group by year;
with t as
(select 2009 as year,1 as month,1000 as saleNumber from dual UNION ALL
select 2009, 2, 1200 from dual UNION ALL
select 2009, 3, 1100 from dual UNION ALL
select 2009, 4, 1150 from dual UNION ALL
select 2010, 1, 1300 from dual UNION ALL
select 2010, 2, 1350 from dual UNION ALL
select 2010, 3, 1250 from dual UNION ALL
select 2010, 4, 1350 from dual
)
select year,
sum(decode(month,1,saleNumber)) as m1,
sum(decode(month,2,saleNumber)) as m2,
sum(decode(month,3,saleNumber)) as m3,
sum(decode(month,4,saleNumber)) as m4
from t
group by year;
with t as
(select 2009 as year,1 as month,1000 as saleNumber from dual UNION ALL
select 2009, 2, 1200 from dual UNION ALL
select 2009, 3, 1100 from dual UNION ALL
select 2009, 4, 1150 from dual UNION ALL
select 2010, 1, 1300 from dual UNION ALL
select 2010, 2, 1350 from dual UNION ALL
select 2010, 3, 1250 from dual UNION ALL
select 2010, 4, 1350 from dual
)
select year,sum(m1) m1,sum(m2) m2,sum(m3) m3,sum(m4) m4
from (select year,
decode(month,1,saleNumber) as m1,
decode(month,2,saleNumber) as m2,
decode(month,3,saleNumber) as m3,
decode(month,4,saleNumber) as m4
from t)
group by year;