mysql:从日期中减去月份并在where claus中用作条件

w1jd8yoj  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(122)

使用以下代码,我想确定发生中断的位置x是否在六个月前发出了警告声明。
在where子句中,我使用 Date_Sub 函数结果作为条件:

SELECT disruption.disruptionDate, warning.warningID, warning.warningDate
FROM disruption
JOIN warning ON disruption.locationId = warning.locationID
WHERE warning.warningDate <= disruption.disruptionDate  
  AND warning.warningDate. >= DATE_SUB(disruption.disruptionDate, INTERVAL 6 MONTH)
ORDER BY disruption.disruptionDate

表规格:
警告表:44814条记录
中断表:962529条记录
我遇到了性能问题,并认为这可能是由于 DATE_SUB 在where子句中的函数。我在这方面的研究几个月来只得出了一个减法。
有没有更有效的方法来写这个声明?
非常感谢您的帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题