的MS SQL Server 2008優化這個查詢
SELECT Action.*
FROM Mailing
INNER JOIN ActionCategoryMailingBunch
ON Mailing.MailingID = ActionCategoryMailingBunch.MailingID
INNER JOIN ActionCategory
ON ActionCategoryMailingBunch.ActionCategoryID =
ActionCategory.ActionCategoryID
INNER JOIN Action
ON ActionCategory.ActionCategoryID = Action.ActionCategoryID
WHERE (Mailing.MailingID = 7)
AND (Mailing.MailingID NOT IN (SELECT MailingID
FROM MailingReport))
AND (Action.ActionID NOT IN (SELECT ActionID
FROM MailingReport))
AND (ActionCategoryMailingBunch.MailingBunchStatusID = 4)
尤其是該塊
(Mailing.MailingID NOT IN (SELECT MailingID FROM MailingReport))
AND (Action.ActionID NOT IN (SELECT ActionID FROM MailingReport))
如果這就是您需要的語義,然後不知道你期望我們處理您的查詢!如果您遇到性能問題,請發佈執行計劃並定義包括索引在內的所有相關表格。雖然由於您只是從Action中選擇列,您可能想使用EXISTS而不是JOIN – 2011-05-25 09:23:56