gpt4 book ai didi

mysql - 使用时间格式选择 +- 2 分钟()

转载 作者:可可西里 更新时间:2023-11-01 08:15:21 25 4
gpt4 key购买 nike

我试图从我的到达时间表中选择的不是准确的到达时间,而是 -+ 2 分钟的查询:

SELECT route from arrivaltimes INNER JOIN stops
ON arrivaltimes.stop_id=stops.stop_id
WHERE weekday = ?
and time_format(arrivaltime,'%H:%i')= time_format(curtime() ,'%H:%i')
and name LIKE ?

如何选择 +- 2 分钟?

最佳答案

如果字段 arrivaltime 是一个 TIME 字段,这应该有效:

SELECT route
FROM arrivaltimes
INNER JOIN stops ON (arrivaltimes.stop_id = stops.stop_id)
WHERE
weekday = ?
AND arrivaltime >= curtime() - INTERVAL 2 MINUTE
AND arrivaltime <= curtime() + INTERVAL 2 MINUTE
AND name LIKE ?

或者您可以使用 BETWEEN运算符(operator):

SELECT route
FROM arrivaltimes
INNER JOIN stops ON (arrivaltimes.stop_id = stops.stop_id)
WHERE
weekday = ?
AND arrivaltime BETWEEN curtime() - INTERVAL 2 MINUTE AND curtime() + INTERVAL 2 MINUTE
AND name LIKE ?

关于mysql - 使用时间格式选择 +- 2 分钟(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30357935/

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