且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL:最后一小时提取行

更新时间:2023-12-05 22:19:16

使用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 : )