我不是 DB 專家,可是我覺得這 SQL command 怪怪的 (@@),你不覺得嗎?
其實本來是用 not in語法來做查詢的動作 但是網路上查了一下有提到not的效率並不高 所以改成用exist
以下是原本的語法
select SN
where SN not in
( select distinct Attr1 from sbcHisMaster where HisTypeNO='A' and Cons_Date >= '2011-03-01' and Cons_Date < '2011-03-10')
and Cons_Date >= '2011-03-01'
and Cons_Date < '2011-03-10'
先用explain來檢查一下你的sql,看看查詢速度的問題可能出在哪裡。
還沒用過explain來檢查執行效率過,來試試看好了
ps 剛剛執行explain試著分析 但是跳出錯誤訊息 找不到預存程式"EXPLAIN" ,小弟SQL是用Microsoft SQL Server 2008