我有一個SQL查詢需要15秒,有時需要1分鐘。 請告訴我,我可以做我的查詢更輕。執行SQL請求花費很多時間
SELECT TOP 100
u.firstName,
u.id as userID,
ueh.targetID,
ueh.opened,
ueh.emailID,
u.phone,
u.gender
FROM dbo.Students u
INNER JOIN dbo.tblEmailHistory ueh
ON ueh.studentID = u.ID
WHERE (CONVERT(date,DATEADD(day,6,ueh.sDate))=CONVERT(date,getdate()))
AND IsNull(u.firstName, '') != ''
AND IsNull(u.email, '') != ''
AND IsNull(u.phone, '') != ''
AND ueh.status = 'sent'
AND ueh.reject_reason = 'null'
AND ueh.targetID = 28
AND ueh.opened = 0
AND u.deleted = 0
AND NOT EXISTS (SELECT ush.smsSendFullDate, ush.studentID FROM dbo.UsersSmsHistory ush WHERE u.id = ush.studentID AND DATEDIFF(DAY,ush.smsSendFullDate,GETDATE()) = 0)
您是否已檢查執行計劃? –