|
 |
|
สอบถามเรื่องการตัด row ที่ซ้ำกันออกหลังจาก query มาแล้ว เขียนอย่างไรคะ |
|
 |
|
|
 |
 |
|
ใช้ GROUP BY เลขที่เอกสาร
แบบนี้ได้ไม๊ครับ
|
 |
 |
 |
 |
Date :
2014-06-09 10:51:36 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้ค่ะ เพราะว่า join ข้อมูลมาหลายตาราง ลองทำดูแล้วมัน error
ตารางที่มีปัญหาคือ ตารางที่ดึงค่าใช้ไปมาแสดง เพราะว่าใน 1 เลขเอกสารจะมีหลายรายการ มันก็เลยแสดงมาหมด
|
 |
 |
 |
 |
Date :
2014-06-09 11:03:00 |
By :
AnnYZaa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ต้อง SUM AS แล้ว GROUP BY ตามที่ คห1. แนะนำ นั้นเหละครับถูกแล้ว
|
 |
 |
 |
 |
Date :
2014-06-09 12:01:08 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
sum as // group by แล้วก็ยังเหมือนเดิมค่ะ
Code (SQL)
select
distinct 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,
pohd.DocuStatus,
SUM(poinvhd.TotabaseAmnt) as TotaBaseAmnt,
(pohd.BillAftrDiscAmnt-poinvhd.TotaBaseAmnt) as Cancel,
CONVERT( VARCHAR( 20 ), pohd.DocuDate, 103 ) as DocuDate ,
CONVERT( VARCHAR( 20 ), pohd.ShipDate, 103 ) as ShipDate
FROM POHD pohd
inner join EMVendor EMVendor on pohd.VendorID = EMVendor.VendorID
inner join emdept emdept on pohd.deptid=emdept.deptid
inner 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,
pohd.VATAmnt,
pohd.RefDocuNo,
pohd.SumGoodAmnt,
pohd.CancelCause,
pohd.CancelFlag,
pohd.BillDiscFormula,
pohd.BillDiscAmnt,
pohd.BillAftrDiscAmnt,
pohd.NetAmnt,
pohd.docustatus,
pohd.onhold ,
pohd.cancelflag,
EMVendor.VendorName ,
EMDept.Deptcode,
pohd.DocuStatus,
pohd.DocuDate,
pohd.ShipDate,
poinvhd.TotabaseAmnt,
order by pohd.docuno" ;
|
 |
 |
 |
 |
Date :
2014-06-09 15:42:50 |
By :
AnnYZaa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|