【发布时间】:2018-05-10 09:41:00
【问题描述】:
我有带有日期字段的“警报”表 - targetDate。
我想选择过去 45 天的所有数据。
我尝试了下面的代码,但它没有返回任何结果...
SELECT userID, refID, `targetDate`
FROM alerts
WHERE type = 'travelSoon'
AND DATEDIFF( CURDATE( ) , targetDate ) > 45
表格
id userID type refID createDate targetDate lastSendDate sent valid
1 26 travelSoon NO 2018-05-02 13:54:25 0000-00-00 2018-05-02 00:00:00 0 1
2 26 travelSoon NO 2018-05-02 13:55:50 2018-06-01 0000-00-00 00:00:00 0 1
3 26 travelSoon DK 2018-05-02 13:56:12 2018-12-01 0000-00-00 00:00:00 0 1
4 26 travelSoon 2018-05-02 13:59:50 0000-00-00 0000-00-00 00:00:00 0 1
5 26 travelSoon 2018-05-02 14:00:09 2018-08-01 0000-00-00 00:00:00 0 1
6 26 travelSoon DK 2018-05-02 14:00:48 2018-08-01 0000-00-00 00:00:00 0 1
7 26 travelSoon 2018-05-02 16:45:18 2018-05-01 0000-00-00 00:00:00 0 1
8 26 travelSoon RO 2018-05-02 16:45:45 2018-04-01 0000-00-00 00:00:00 0 1
【问题讨论】:
-
什么是 targetDate 数据类型?
-
@DT - 日期 ....
-
MySQL、SQL Server、甲骨文...?
-
NOW() 函数返回 MySQL 中的当前日期。使用它和 45 天的硬编码时间戳来获取最旧的可能条目的时间戳。然后 SELECT * FROM table WHERE timestamp > var.