我有2個兩個表,顯示重複SQL與在
Invoice (ordernumber, status(which assign to InvoiceStatuses), etc)
和
InvoiteStatuses(status name, statusid)
我需要檢查發票副本只爲訂單編號,但where status != statusID
(其中名稱爲「取消」)
SELECT A.*
FROM Invoices A
JOIN InvoiceStatuses b
(
SELECT * FROM InvoiceStatuses
WHERE InvoiceStatus = 'CANCELLED'
) B
ON A.InvoiceStatus!=b.InvoiceStatusID
WHERE exists (SELECT OrderNumber
FROM Invoices c
WHERE a.OrderNumber = c.OrderNumber
GROUP BY OrderNumber
HAVING COUNT(*)>1)
請寫出你想要做什麼樣的文字說明,而不是隻寫你想要的話在英語中WHERE子句。目前還不完全清楚你想在這裏做什麼。 – 2014-09-11 10:14:14
你在'invoices'表中有主鍵列嗎? – Bulat 2014-09-11 10:29:46
是的,我擁有它。 – NoNameR 2014-09-11 10:34:48