select t2.main_ditch, t3.ditch_name,  count(*) round(sum(c.order_money))/100 as amount,t3.id 
        from  t_main_ditch t3  right join t_cas_userst t2 on t2.main_ditch=t3.ditch_no  
        right join t_sub_ditch ts on ts.ditch_no=t2.sub_ditch 
        right join t_cas_trade t on t.cas_id=t2.id right join t_combo c on t.combo_id=c.id 
        group by t2.main_ditch,t3.ditch_name,t3.id, ts.main_ditch_id,t3.ditch_no 
        having ts.main_ditch_id=t3.id and  t2.main_ditch=t3.ditch_no 我要求  sum( count(*)) ,sum( amount) 如何去写?  

解决方案 »

  1.   

    -- 先说:sum( count(*)) 
    -- 既然已经有 count(*) 了,为什么还要用 sum()函数去嵌套呢? 你不觉得是画蛇添足么?
      

  2.   

    -- 而且聚集函数是不能这样嵌套滴:scott@TBWORA> select deptno, sum(count(empno)) from emp group by deptno;
    select deptno, sum(count(empno)) from emp group by deptno
           *
    第 1 行出现错误:
    ORA-00937: 不是单组分组函数
    scott@TBWORA> select deptno, count(empno) from emp group by deptno;    DEPTNO COUNT(EMPNO)
    ---------- ------------
            30            6
            20            5
            10            3scott@TBWORA> select deptno, sum(count(*)) from emp group by deptno;
    select deptno, sum(count(*)) from emp group by deptno
           *
    第 1 行出现错误:
    ORA-00937: 不是单组分组函数
      

  3.   

    已经用count(*)函数,还用sum()函数嵌套呢?这是没有意义的。
      

  4.   

    我现在 查询出来是~
     a         b    c       d       e  
    1111 4510 1 14 2 
    4551 1710 3 42 2
    1534 5310 4 65 2
    我要算 这个 c ,d 的总合 在 select t2.main_ditch as a1, t3.ditch_name as a2 ,
             count(*) as a3, round(sum(c.order_money))/100 as a4,t3.id  as a5
            from  t_main_ditch t3  right join t_cas_userst t2 on t2.main_ditch=t3.ditch_no  
            right join t_sub_ditch ts on ts.ditch_no=t2.sub_ditch 
            right join t_cas_trade t on t.cas_id=t2.id right join t_combo c on t.combo_id=c.id 
            group by t2.main_ditch,t3.ditch_name,t3.id, ts.main_ditch_id,t3.ditch_no
            having ts.main_ditch_id=t3.id and  t2.main_ditch=t3.ditch_no 
    这个基础上  如何解得?
      

  5.   


    我再外面嵌套的话~这个速度会不会NNNNNN慢的?