我有一个mySQL视图,我希望能够找到所有expirationDate为N天的记录。例如,我想找到所有过期日期正好是90天以后的记录,这样我就可以通过电子邮件通知他们课程即将过期。dateCompleted和expirationDate都是datetime类型。
结构:

id  can firstName   lastName    email   course  curriculum  group   stageNum    stage   dateCompleted   expirationDate

数据示例:
1   123456789   John    Smith   [email protected]    PHS Conflict of Interest    Conflict of Interest mini-course    Conflict of Interest    1   Stage 1 2012-12-07 02:52:24 2015-12-07 02:52:24

最佳答案

从现在起的90天内,这将为您带来结果:

SELECT * FROM courses WHERE DATE(expirationDate) = DATE_ADD(CURRENT_DATE(), INTERVAL 90 DAY)

10-06 14:06