用于显示过去 60+ 行的 SQL 查询 [英] SQL query to show rows that are 60+ in the past
本文介绍了用于显示过去 60+ 行的 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库中有一行日期时间为
I have a row in my database with the datetime as
2013-11-07 13:04:57
然后我运行这个查询:
SELECT * from customer_communication
WHERE customer_seq = '276'
and datetime < DATE_SUB(DATE(now()), INTERVAL 60 DAY)
order by datetime DESC
所以它不应该返回这一行
so it should not be returning this row
我想显示过去 60 天以上日期时间的所有行
i want to show all rows with a datetime that are 60+ days in the past
推荐答案
问题是您当前的查询将选择早于一个 datetime
值的行.您需要将比较符号更改为:
The problem is that your current query will select rows that are older than one datetime
value. You need to change comparison sign to:
datetime > DATE_SUB(DATE(now()), INTERVAL 60 DAY)
日期 2013-11-07 13:04:57 过去 60 多天.
And date 2013-11-07 13:04:57 more than 60 days in the past.
这篇关于用于显示过去 60+ 行的 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文