我想減少我的SQL請求的處理時間(實際上它運行10分鐘...) 我認爲問題來自嵌套的SQL查詢。 (對不起,我的英語,我是法國學生)SQL請求太長...如何簡化?
SELECT DISTINCT `gst.codeAP21`, `gst.email`, `gst.date`, `go.amount`
FROM globe_statistique
JOIN globe_customers ON `gst.codeAP21`=`gc.codeAP21`
JOIN globe_orders ON `gc.ID`=`go.FK_ID_customers`
WHERE `gst.page` = 'send_order'
AND `gst.date` = FROM_UNIXTIME(`go.date`,'%%Y-%%m-%%d')
UNION
SELECT DISTINCT `gst.codeAP21`, `gst.email`, `gst.date`, '-'
FROM globe_statistique
WHERE `gst.page` NOT LIKE 'send_order' "
AND (`gst.codeAP21`,`gst.date`) NOT IN
(SELECT `gst.codeAP21`,`gst.date` FROM globe_statistique
WHERE `gst.page`='send_order');
感謝
重新寫NOT IN的LEFT JOIN。並從不喜歡的測試切換到!=。 – jarlh
我試圖改變不喜歡!=但它是一樣的,但我刪除嵌套的查詢和它的工作,所以問題來自休息的查詢... 我的表globe_statistique:56000行 – Gabi
你的意思是,第一個SELECT是慢的嗎? – jarlh