ต้องการ sum คอลัมน์ poinvhd.TotaBaseAmnt เพื่อรวมค่า เฉพาะที่มี pohd.DocuNo เหมือนกัน แต่พอใส่ GROUP BY poinvhd.TotaBaseAmnt แล้วมัน error
Column 'POHD.RefDocuNo' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Code (SQL)
select
pohd.DocuNo,
pohd.RefDocuNo,
pohd.VATAmnt,
pohd.SumGoodAmnt,
pohd.CancelCause,
pohd.CancelFlag,
pohd.BillDiscFormula,
pohd.BillDiscAmnt,
pohd.BillAftrDiscAmnt,
pohd.NetAmnt NetAmnt,
(pohd.docustatus)docustatus,
(pohd.onhold)onhold ,
(pohd.cancelflag)cancelflag,
EMVendor.VendorName ,
EMDept.Deptcode,
poinvhd.TotaBaseAmnt,
(pohd.BillAftrDiscAmnt-poinvhd.TotaBaseAmnt) as Cancel,
pohd.DocuStatus,
CONVERT( VARCHAR( 20 ), pohd.DocuDate, 103 ) as DocuDate ,
CONVERT( VARCHAR( 20 ), pohd.ShipDate, 103 ) as ShipDate
FROM POHD pohd
left join EMVendor EMVendor on pohd.VendorID = EMVendor.VendorID
left join emdept emdept on pohd.deptid=emdept.deptid
left join poinvhd on poinvhd.pono=pohd.docuno
where pohd.docudate between '2013/01/01' and '2013/03/01'
and pohd.docutype='305' and pohd.MultiCurr = 'N' and pohd.cancelflag='y'
GROUP BY pohd.docuno
order by pohd.docuno