日期:2014-05-16 浏览次数:21186 次
with table_ta as
(select 1 "TYPE",5 "LEV",100 "NUM",2010 "YEAR" from dual
union all
select 1 , 6 ,101,2010 from dual
union all
select 2 , 7 ,200,2010 from dual
union all
select 2 , 7 ,201,2011 from dual
union all
select 3 , 5 ,300,2012 from dual
union all
select 3 , 5 ,320,2012 from dual
)
--方法一
select a.lev,sum(decode(a.YEAR,2010,a.num,0)) "2010",
sum(decode(a.YEAR,2011,a.num,0)) "2011",
sum(decode(a.YEAR,2012,a.num,0)) "2012"
from table_ta a group by a.lev order by a.lev
--方法二
select a.lev,sum(case a.YEAR when 2010 then a.num else 0 end) "2010",
sum(case a.YEAR when 2011 then a.num else 0 end) "2011",
sum(case a.YEAR when 2012 then a.num else 0 end) "2012"
from table_ta a group by