如何从多个连接查询中删除冗余数据

时间:2018-06-07 07:54:20

标签: sql-server

你好,我想从多个连接查询中删除冗余数据。但是我在运行此查询后会收到重复的数据。

发票表

INVOICE

INVOICE_DETAILS表

INVOICE_DETAILS

JOB_DETAILS表

JOB_DETAILS

IMP_BILLING_TERMS_DETAILS表

IMP_BILLING_TERMS_DETAILS

运行此查询后的结果 RESULT

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'

0 个答案:

没有答案