我的MySQL查询执行时间过长

时间:2019-07-12 05:36:49

标签: mysql sql

我正在我的网站上运行mysql查询,但是这花费了太多时间,任何人都可以帮助我减少它的运行时间。预先感谢

SELECT ABS(DATEDIFF(MAX(lcd2.originaldate), lcd1.originaldate)) AS IP_LT_Seen
  FROM (SELECT lcd1.id
             , l1.mphone
             , l1.wphone
             , lcd1.leadID
             , CAST(CONCAT(l1.originaldate, ' ', l1.originaltime) AS datetime) AS originaldate 
          FROM LeadsCashDataIndexed lcd1 
               INNER JOIN Leads l1 
                       ON l1.id = lcd1.leadID
         WHERE lcd1.ip = '192.168.1.1') AS lcd1
        LEFT JOIN (SELECT lcd2.id
                        , l2.mphone
                        , l2.wphone
                        , lcd2.leadID
                        , CAST(CONCAT(l2.originaldate, ' ', l2.originaltime) AS datetime) AS originaldate 
                     FROM LeadsCashDataIndexed lcd2 
                          INNER JOIN Leads l2 
                                  ON l2.id = lcd2.leadID
                    WHERE lcd2.ip = '192.168.1.1') AS lcd2
               ON lcd1.originaldate > lcd2.originaldate
              AND lcd1.originaldate <= DATE_ADD(lcd2.originaldate, INTERVAL 180 DAY)
 WHERE lcd1.leadID = 1;

0 个答案:

没有答案