我正在尝试查询和计算特定时间段内的状态, 假设我想从现在开始查询和统计最近12小时的状态
select count(*) as result
from table_events_log
where status ='COLD' AND event_timestamp > (NOW(),INTERVAL 12 HOUR) ;
我一直收到语法错误,这里有任何提示我在这里缺少
答案 0 :(得分:1)
您的查询并不遥远。您只需从当前时间减去 12小时的间隔,即:
WHERE event_timestamp > (NOW() - INTERVAL '12 hours')
完整查询:
SELECT COUNT(*) AS result
FROM table_events_log
WHERE status = 'COLD' AND event_timestamp > (NOW() - INTERVAL '12 hours')