select a1,sum(a2) as groupTotal from table where a3='2005-02-14' group by a1 with rollup

解决方案 »

  1.   

    一楼是sql server中写法,oracle 中这么写select a1,sum(a2) as groupTotal from table where a3='2005-02-14' group by rollup(a1)
      

  2.   

    多谢 duanzilin(寻)    我用这个找出来合计是合计,不过他只是增加一条记录,而且a1这栏会是空的,那我怎么取出这个值呢!,请赐教!
      

  3.   

    因为我想用分组的数量去除上我想要合计出来的数量,我想用一个SQL解决,看来不行啦!
      

  4.   

    你想要的结果是可以写出来的!
    但不是很方便!
    select a1,a2,
          (select sum(a2) from (select a1,sum(a2) a2,a3 from table group by a1,a3)
            where a3 ='2005-02-14') total
       from (select a1,sum(a2) a2,a3 from table group by a1,a3) 
    where a3 ='2005-02-14';
      

  5.   

    select a1,sum(a2) as groupTotal, sum(a2) over() total from table where a3='2005-02-14' group by a1
      

  6.   

    楼主要这样的结果吗? a       7/(7+3)= 0.7      
     b       3/(7+3)= 0.3可以这样写:select a1,ratio_to_report(sum(a2)) over() rate from  table where a3='2005-02-14' group by a1