首先:没有with rollup的方法。
方法一:group by rollup实现小计、合计
方法二:利用union查询拼接
其他的方法后面再补充~~
select to_char(rownum),a.clientaccnumber,a.clientaccount,a.amount,a.contract_numberfrom (select clientaccnumber,clientaccount,amount,contract_number as contract_numberfrom lc_abc_export_data laedwhere deduct_info_id = '3b6587b1f5ad4488879f99a810fb4097'and paynumber is not nullorder by cast(serialno as int)) a
union
select '合计', '', '', sum(a.amount), ''from (select clientaccnumber,clientaccount,amount,contract_number as contract_numberfrom lc_abc_export_data laedwhere deduct_info_id = '3b6587b1f5ad4488879f99a810fb4097'and paynumber is not nullorder by cast(serialno as int)) a;
select decode(grouping(to_char(rownum)),1,'合计',to_char(rownum)),a.clientaccnumber,a.clientaccount,sum(a.amount),a.contract_numberfrom (select clientaccnumber,clientaccount,amount,contract_number as contract_numberfrom lc_abc_export_data laedwhere deduct_info_id = '3b6587b1f5ad4488879f99a810fb4097'and paynumber is not nullorder by cast(serialno as int)) agroup by rollup((to_char(rownum),a.clientaccnumber,a.clientaccount,a.contract_number))