Gahh ..令我沮喪。教科書要求我們重寫下面的語句而不使用共同相關的子查詢。Co-Related SubQuery
SELECT DISTINCT V.VENDOR_NAME, I.INVOICE_NUMBER, I.INVOICE_DATE, I.INVOICE_TOTAL
FROM VENDORS V
JOIN INVOICES I
ON V.VENDOR_ID = I.VENDOR_ID
WHERE I.INVOICE_DATE IN
(SELECT MIN(INVOICE_DATE) FROM INVOICES IV WHERE IV.VENDOR_ID = V.VENDOR_ID)
AND I.INVOICE_NUMBER IN
(SELECT MIN(INVOICE_NUMBER) FROM INVOICES IV WHERE IV.VENDOR_ID = V.VENDOR_ID)
ORDER BY V.VENDOR_NAME
我該怎麼做?我想不出反正它重新寫無子查詢:S
有點奇怪的查詢,如果'INVOICE_DATE'和'INVOICE_NUMBER'不是它們的同一發票的最小值,它根本不會顯示任何結果。 – 2013-02-20 17:49:23
我想知道爲什麼教科書對此查詢有DISTINCT。這有點代碼味道,他們沒有在涉及的表格上設置正確的唯一性約束,或者沒有仔細檢查。 – 2013-02-21 03:28:21