Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 829 Bytes

fetch_rows_added_last_hour.md

File metadata and controls

32 lines (23 loc) · 829 Bytes

查询最近一小时内记录

经常要查询日志数据库中最近1小时加入的数据,结合DATE_SUB()NOW()函数方法如下:

select count(*) as cnt
from  log
where date >= DATE_SUB(NOW(),INTERVAL 1 HOUR); 

查询最近30分钟记录

可以使用(now() - interval 30 minute)

select count(*) as cnt
from  log
where date >= (NOW() - INTERVAL 30 minute); 

使用DATE_SUB()函数也可以:

select count(*) as cnt
from  log
where date >= DATE_SUB(NOW(), INTERVAL 30 minute); 

参考