oracle 擴展函數用sql 加合計行

1   rollup()  推薦

 rollup()是group by的一個擴展函數,初步的感覺是,可以多個列進行group by,然後分別進行統計。

示例 (給group列加rollup)

select  CENTNO,
  count(name) 賬戶數,count(distinct type)類型,sum(yue) 餘額
  from table e 
where to_char(e.jzdate,'yyyymmdd')='20200101'  
group by rollup(CENTNO) 
order by CENTNO asc

2  用union (缺點,腳本複雜時較長,效率稍低)

select AAA,BBBB  from table
union
select '合計',' ',' ',sum(AAAA),sum(BBBB) from table;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章