oracle group by rollup

  1. select sum(a.dqh) as dqh, nvl(c.zdmc, '合计') as dqmc, sum(a.fsje) as ckje, sum(b.fsje) as jfje from   
  2. (select dqh, sum(fsje) as fsje from   
  3. (select b.dqh, a.fsje   
  4. from table_test1 a, table_test2 b   
  5. where   
  6. a.hyzh = b.bzjzhbh   
  7. and a.ywbz in ('1011','2000','1999')   
  8. union all   
  9. select zddm as dqh, 0 as fsje from xtgl_sjzd where zdlbdm = 'DQH')   
  10. group by dqh) a,   
  11. (select dqh, -sum(fsje) as fsje from   
  12. (select b.dqh, a.fsje   
  13. from table_test1 a, table_test2 b   
  14. where   
  15. a.hyzh = b.bzjzhbh   
  16. and a.ywbz in ('1051','1052','1053')  
  17. union all   
  18. select zddm as dqh, 0 as fsje from xtgl_sjzd where zdlbdm = 'DQH')  
  19. group by dqh) b,  
  20. xtgl_sjzd c  
  21. where a.dqh = b.dqh and a.dqh = c.zddm and c.zdlbdm = 'DQH'  
  22. group by rollup(c.zdmc)   
  23. order by dqh, decode(dqmc,'合计',9,1)  
  1. da shang
    donate-alipay
               donate-weixin weixinpay

发表评论↓↓