oracle 统计结合横向和纵向统计得结果

select nvl(t.NAME, '合计') NAME,
       sum(decode(t.vehicletypename, 'A1', j.totalhours, 0.00)) as A1,
       sum(decode(t.vehicletypename, 'B2', j.totalhours, 0.00)) as B2,
       sum(decode(t.vehicletypename, 'C1', j.totalhours, 0.00)) as C1,
       sum(decode(t.vehicletypename, 'C2', j.totalhours, 0.00)) as C2,
       sum(decode(t.vehicletypename, 'C3', j.totalhours, 0.00)) as C3,
       sum(decode(t.vehicletypename, 'C4', j.totalhours, 0.00)) as C4,
       sum(decode(t.vehicletypename, 'A3', j.totalhours, 0.00)) as A3,
       sum(decode(t.vehicletypename, 'B1', j.totalhours, 0.00)) as B1,
       sum(decode(t.vehicletypename, 'A2', j.totalhours, 0.00)) as A2,
       sum(j.totalhours) as "合计"
  from personinfo_view t, person_all_hours j
 where t.ID = j.personid
 group by rollup(t.NAME)

 

posted on 2013-06-14 10:34  呼嘎嘎  阅读(1874)  评论(0)    收藏  举报

导航