oracle纵向统计列之和

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cxws110/article/details/86527690

select * from (
    select id, dept,deptCode,projCode,
       prpjdepartname,
       cost_type,
       cost_type_id,budget_year,
       budget_money,
       budget_money_add,
       budget_moneyhj
  from w_fm_budget
union
select null,t.dept,deptCode,projCode,
       t.prpjdepartname,
       '项目部预算合计',null,budget_year,
       sum(t.budget_money),
       sum(t.budget_money_add),
       sum(t.budget_moneyhj)
  from w_fm_budget t
 group by t.dept, t.prpjdepartname,deptCode,projCode,budget_year
union
select null,t.dept,deptCode,null,
       null,
       '费用归属部门预算合计',null,budget_year,
       sum(t.budget_money),
       sum(t.budget_money_add),
       sum(t.budget_moneyhj)
  from w_fm_budget t
 group by t.dept,deptCode,budget_year
 union
select null,null,null,null,
       null,
       '总预算额',null,t.budget_year,
       sum(t.budget_money),
       sum(t.budget_money_add),
       sum(t.budget_moneyhj)
  from w_fm_budget t
  group by t.budget_year
 ) 
 where 1=1
 and budget_year=2018
  order by abs(deptCode),projCode,cost_type_id

结果如下:

猜你喜欢

转载自blog.csdn.net/cxws110/article/details/86527690