Mysql 如何根据日期获取记录

Mysql 如何根据日期获取记录,mysql,Mysql,您好,我需要获得到期日临近的记录列表(即,如果产品出口日期为2013年12月11日,管理员对此产品发出的警报为5天。管理员将从2013年12月6日起收到警报),以下是我的表格 +---------+--------------+-------------------+ | id | due_date | reminder_type | +---------+--------------+-------------------+ | 1 | 2013-12-

您好,我需要获得到期日临近的记录列表(即,如果产品出口日期为2013年12月11日,管理员对此产品发出的警报为5天。管理员将从2013年12月6日起收到警报),以下是我的表格

+---------+--------------+-------------------+
|   id    |   due_date   |   reminder_type   |
+---------+--------------+-------------------+
|   1     |  2013-12-11  |    5 day          |
|   2     |  2014-12-11  |    5 month        |
|   3     |  2015-12-11  |    5 day          |
|   4     |  2013-12-19  |    5 day          |
+---------+--------------+-------------------+
SELECT * , CONCAT( 'date_add(NOW( ) ,INTERVAL', reminder_type, ')' ) AS x
FROM `alerts` 
HAVING `due_date` = x
我尝试了上面的查询,但它不起作用

试试这个。 对于过期数据,您可以再添加一列,如active或not active。 以下将根据提醒类型和到期日通过关闭记录进行订购
它看起来很容易查询,但工作非常完美

SELECT * FROM alerts ORDER BY due_date, reminder_type DESC
如果再添加一个列init,则查询将是:

SELECT * FROM alerts WHERE active='Y' ORDER BY due_date, reminder_type DESC

通过添加列,您可以确定有多少记录过期。

这不是我需要的。