我正在尝试创建一个查询,它将获得在过去 10 秒内插入的结果:
SELECT *
FROM table
WHERE client_id = 1
AND hash = 'x'
AND insert_time >= current_timestamp - **10 seconds**
我一直在寻找如何从当前时间戳中减去 10 秒,但我还没有成功。
最佳答案
由于reference你应该使用 SUBTIME
...
and insert_time >= SUBTIME(current_timestamp,'0 0:0:10.000000');
或者,您可以使用 INTERVAL
,如下所示:
...
and insert_time >= SUBTIME(current_timestamp, INTERVAL 10 SECOND);
请注意,由于 reference
When invoked with the INTERVAL form of the second argument, SUBDATE() is a synonym for DATE_SUB().
关于mysql - 如何从当前时间戳中减去秒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37188862/