您需要將兩張表連同LEFT JOIN
一起加入,然後查看付款日期> 31-MAR-14。試試這樣:
SELECT INVOICE.INVOICE_NUMBER, INVOICE.INVOICE_DATE, PAYMENT.PAYMENT_NO, PAYMENT.INVOICE_NUMBER
FROM INVOICE
LEFT JOIN PAYMENT ON INVOICE.INVOICE_NUMBER = PAYMENT.INVOICE_NUMBER
WHERE PAYMENT.Date_of_payment > '3/31/2014'
ORDER BY INVOICE.INVOICE_NUMBER;
這看起來是2014年3月31日之後所有付款。您可能需要添加另一個條件,以限制您要查找的發票。
要檢查尚未付款的付款,請查看PAYMENT表中的任何字段爲空的位置。 SQL是這樣的:
SELECT INVOICE.INVOICE_NUMBER, INVOICE.INVOICE_DATE, PAYMENT.PAYMENT_NO, PAYMENT.INVOICE_NUMBER
FROM INVOICE
LEFT JOIN PAYMENT ON INVOICE.INVOICE_NUMBER = PAYMENT.INVOICE_NUMBER
WHERE INVOICE.INVOICE_DATE = '3/31/2014'
AND PAYMENT.PAYMENT_NO IS NULL
ORDER BY INVOICE.INVOICE_NUMBER;
留在這種情況下,JOIN總是發票表返回值,但如果支付尚未進入尚未到位的付款方式可能返回NULL值。檢查AND PAYMENT.PAYMENT_NO IS NULL
會告訴您尚未付款。
您是否在付款中有一列指定付款的當天? – steinmas
是的,我將'Payment_No''Payment_Method''Date_of_payment'和'Invoice_number'作爲外鍵。在付款表中。 –
因此,您正在查找3月31日尚未支付的所有發票?這是否意味着付款表中有一個條目,日期是> 3月31日?或者在付款表中根本沒有輸入特定發票。 – steinmas