选择一小时内创建的所有记录 [英] select all records created within the hour
本文介绍了选择一小时内创建的所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
startTimestamp < date_sub(curdate(), interval 1 hour)
上面的(子)查询是否会返回在一小时内创建的所有记录?如果不是,请给我看一个正确的人吗?完整的查询可能如下所示:
Will the (sub)query above return all records created within the hour? If not will someone please show me a correct one? The complete query may look as follows:
select * from table where startTimestamp < date_sub(curdate(), interval 1 hour);
推荐答案
而不是 CURDATE()
,而是使用 NOW()
并使用> =
而不是<
,因为您希望时间戳大于一个小时前的时间戳. CURDATE()
仅返回日期部分,而 NOW()
返回日期和时间.
Rather than CURDATE()
, use NOW()
and use >=
rather than <
since you want timestamps to be greater than the timestamp from one hour ago. CURDATE()
returns only the date portion, where NOW()
returns both date and time.
startTimestamp >= date_sub(NOW(), interval 1 hour)
例如,在我的时区是12:28
For example, in my timezone it is 12:28
SELECT NOW(), date_sub(NOW(), interval 1 hour);
2011-09-13 12:28:53 2011-09-13 11:28:53
总而言之,您需要的是:
All together, what you need is:
select * from table where startTimestamp >= date_sub(NOW(), interval 1 hour);
这篇关于选择一小时内创建的所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文