正在获取上一个小时添加的行 [英] Fetching rows added last hour
本文介绍了正在获取上一个小时添加的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将登录记录记录在一个表中.我有ID,IP,日期和时间的列.从该登录记录中,我想获取仅在最近一个小时内进行的登录.
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.
我正在遍历有关时间和日期函数的MySQL文档,但似乎无法正确组合它们.
I'm sweeping through the MySQL docs on time and date functions, but I just can't seem to combine them correctly.
有人可以帮我吗?
推荐答案
使用DATE_SUB()和Now()函数:
Make use of the DATE_SUB() and Now() functions:
select count(*) as cnt
from log
where date >= DATE_SUB(NOW(),INTERVAL 1 HOUR);
希望对您有帮助:)
这篇关于正在获取上一个小时添加的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文