你好,我想从多个连接查询中删除冗余数据。但是我在运行此查询后会收到重复的数据。
发票表
INVOICE_DETAILS表
JOB_DETAILS表
IMP_BILLING_TERMS_DETAILS表
SELECT DISTINCT
INV.bill_ID,
INV.Bill_No,
Agency_Charges = (SELECT DISTINCT IBTD.Amount_Paid
FROM Invoice_Details INV_details inner join Imp_Billing_Terms_Details IBTD on INV_details.Billing_Term_ID_Auto = IBTD.Billing_Terms_ID_Auto AND IBTD.Billing_Term_ID = '1033'
WHERE INV_details.Invoice_ID = INV.bill_ID)
FROM Invoice INV inner JOIN Job_Details JD on INV.Job_ID = JD.Job_ID
WHERE JD.Job_No is not null and INV.Bill_No is not null and JD.Gen_Bill = 'Y' AND JD.Company_ID='2'