gpt4 book ai didi

python - SQL 仅选择最近 5 分钟的记录

转载 作者:行者123 更新时间:2023-11-29 23:55:23 24 4
gpt4 key购买 nike

我想获取最近 5 分钟的记录。我目前正在使用从该网站获得的代码:

select * from table where timestamp between curtime() and timestamp(date_sub(now(), interval 5 minute))

但它对我不起作用,它每隔 5 分钟返回我的所有记录。例如,我将有几条时间戳为 2014-07-30 15:40:02 的记录,然后我将得到 5 分钟的间隙,并获取几条时间戳为 2014-07-30 15:45 的记录:02。

最佳答案

这是您的 where 子句:

where timestamp between curtime() and timestamp(date_sub(now(), interval 5 minute))

在本例中,第一个界限大于第二个界限,因为您要从当前时间中减去 5 分钟。这实际上不应该匹配任何东西,因为:

where x between y and y - 5

应始终返回一个空集。界限是有序的。也许交换它们会有所帮助:

where timestamp between timestamp(date_sub(now(), interval 5 minute)) and curtime()

但是,如果您没有 future 的时间戳,只需执行以下操作:

where timestamp >= timestamp(date_sub(now(), interval 5 minute))

关于python - SQL 仅选择最近 5 分钟的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25404075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com