我在表中有两个时间-打开时间和关闭时间。
Open_time. Selected time Close_time
06:00:00 09:23:46 23:45:00
09:00:00 09:23:46 00:00:00
09:00:00 09:23:46 23:00:00
09:00:00 09:23:46 23:00:00
06:00:00 09:23:46 23:45:00
06:00:00 09:23:46 04:00:00
06:00:00 09:23:46 02:00:00
我只需要选择打开和关闭之间的时间,但我的表情有一些问题。
SELECT open_from, close_at FROM restrnt WHERE (time('now', '+10 hours') BETWEEN restaurants.open_from and restaurants.close_at)
06:00:00 23:45:00
09:00:00 23:00:00
09:00:00 23:00:00
06:00:00 23:45:00
它只选择00:00:00之前的时间,但我需要它在那篇文章中找到。
SELECT time('now','+5 hours') as nowTime, time(restaurants.open_from) as openTime, time(restaurants.close_at) as closeTime,
CASE
WHEN time(restaurants.open_from) > time(restaurants.close_at) THEN time('now','+5 hours') >= time(restaurants.open_from) or time('now','+5 hours') < time(restaurants.close_at)
when time(restaurants.open_from) < time(restaurants.close_at) THEN time('now','+5 hours') >= time(restaurants.open_from) and time('now','+5 hours') < time(restaurants.close_at)
END is_opened
from restaurants
WHERE is_opened >0
就我而言,它是有效的,就像我需要的那样。输出
06:16:03 06:00:00 23:45:00 1
06:16:03 06:00:00 23:45:00 1
06:16:03 06:00:00 04:00:00 1
06:16:03 06:00:00 02:00:00 1