MYSQL查询以1分钟为间隔返回记录

时间:2016-12-17 19:41:40

标签: mysql

有1分钟间隔返回记录的问题。例如2016-12-17 21:38我只需要返回1分钟beetwen 2016-12-17 21:372016-12-17 21:38。但我注意到它在2016-12-17 20:00之间返回 - 所有时间都更大2016-12-17 21:38

问题出在哪里?

SELECT * FROM appointments 
WHERE id_user = 84 
AND hash = 'new' 
AND end_datetime > DATE_SUB(NOW(),INTERVAL 1 MINUTE)

end_datetime - mysql中的日期时间

2 个答案:

答案 0 :(得分:0)

以下查询应该有效:

SELECT * FROM appointment
WHERE end_date > DATE(curtime()-INTERVAL 1 MINUTE);

这是 SQL Fiddle

答案 1 :(得分:0)

试试这个:

SELECT * FROM appointments 
WHERE id_user = 84 
AND hash = 'new' 
AND end_datetime BETWEEN NOW() - INTERVAL 1 MINUTE AND NOW()