我有一个像这样的表
+----+------------+------------+
| id | expiry | timestamp |
+----+------------+------------+
| 1 | 2018-11-29 | 2018-11-01 |
| 2 | 2018-12-27 | 2018-11-01 |
| 3 | 2019-01-31 | 2018-11-01 |
| 4 | 2018-11-29 | 2018-11-01 |
| 5 | 2018-12-27 | 2018-11-01 |
+----+------------+------------+
如何查询expiry
距timestamp
少于30天的所有记录?即
timestamp + 30 days > expiry
答案 0 :(得分:2)
我建议:
where expiry < timestamp + interval 30 day
答案 1 :(得分:0)
您可以尝试
SELECT * FROM table_name WHERE DATE_ADD(TIMESTAMP , INTERVAL 30 DAY) > expiry;