MySQL:最后一小时提取行 [英] MySQL: Fetching rows added last hour
本文介绍了MySQL:最后一小时提取行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过MySQL文档在时间和日期功能上感冒,但是我似乎无法正确地组合它们。
有人可以帮我吗?
解决方案
使用DATE_SUB()和Now()函数:
从$ log
中选择count(*)作为cnt
其中date> = DATE_SUB(NOW(),INTERVAL 1 HOUR);
希望它可以帮助你:)
I keep a record of logins in a table. I have columns for id, ip, date and time. From that record of logins I wanna fetch logins made only in the last hour.
I'm sweaping through the MySQL docs on time and date functions, but I just can't seem to combine them correctly.
Can somebody help me?
解决方案
Make use of the DATE_SUB() and Now() functions:
select count(*) as cnt
from log
where date >= DATE_SUB(NOW(),INTERVAL 1 HOUR);
Hope it helps you : )
这篇关于MySQL:最后一小时提取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文