我想减少我的SQL请求的处理时间(实际上它运行10分钟...)
我认为问题来自嵌套的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');


谢谢

最佳答案

尝试这个:

但我建议重命名您的列名并删除点。
还使用EXPLAIN找出查询缓慢的原因并添加正确的索引

10-08 20:21