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;