本帖最后由 huang_w 于 2010-10-22 17:09:57 编辑

解决方案 »

  1.   

    with a as (
    select 'a' A, 'b' B ,5 C ,2 D from dual
    union all 
    select 'w', 'b', 1, 3 from dual
    union all
    select 'x' ,'x' ,3 ,1 from dual
    )
    select decode(grouping(A),1,'合計',A) A
      ,B,sum(C) C,SUM(D) D 
    from a
    group by rollup ((a,b))
      

  2.   

    select (case when grouping(A)=1 then '合计' else A end),
    B,
    sum(C),sum(d) from ta
    group by  rollup(A,B)
      

  3.   

    select * from table union select '随便写得和A的类型一致','合计',select sum(c) from table,sun(d) from table
      

  4.   

    回复真快啊!谢谢大家!
    一楼的rollup 多套一个括号可以实现我的要求
    三楼rollup少一个括号,会多出小合计来