select a,b,a+b as c
     from xxx
     group by a,b,a+b

select a,b,max(a+b) as c
     from xxx
     group by a,b

解决方案 »

  1.   

    select a.mfpo_code,a.vendor_code,sum(c.qty) as stock_qty,b.raw_trans_date
            sum(b.recvd_pound),
            (sum(c.qty)/b.recvd_pound) as balance
      from mms_mfpo a,raw_mat_in b,mms_mfpo_qty c, mms_mfpo_mtl_grp d,  
      group by c.clr_code,a.mfpo_code,a.vendor_code,b.raw_trans_date;   貼出原代碼,省略了where,就是最後一個(sum(c.qty)/b.recvd_pound) as balance
    是計算出來的,不將該列放在group by 提示不是一個group by 表達式,放在group by中,又說不是一個群體函數。怎麼辦?
     
      

  2.   

    group by中加入b.recvd_pound即可
      

  3.   

    或者将sum(c.qty)/b.recvd_pound改为sum(c.qty)/max(b.recvd_pound)