用oracle的rollup函数进行合计操作

需求:
用oracle的rollup函数进行合计操作

公式:
select decode(a,null,’合计’,a) ,b,sum(c) c from t group by rollup((a,b,c))

实例:
表名,T_BC_BILLINGPARTICLE;
需要合计的字段名,billingqty, primaryprice, primaryamount, subtotal;
不需要合计的字段名,instancestring;

SQL:

select decode(instancestring, null, '合计', instancestring) instancestring,
       sum(billingqty) billingqty,
       sum(primaryprice) primaryprice,
       sum(primaryamount) primaryamount,
       sum(subtotal) subtotal
  from T_BC_BILLINGPARTICLE t
 group by rollup(instancestring)

效果:
用oracle的rollup函数进行合计操作_第1张图片

你可能感兴趣的:(oracle统计)