Endtime
を含む各行を2行に分割できます 翌日の:
WITH cte AS (
SELECT *, Weekday day, Starttime time1, Endtime time2 FROM user_time
WHERE Starttime < Endtime
UNION ALL
SELECT *, Weekday, Starttime, '23:59' FROM user_time
WHERE Starttime > Endtime
UNION ALL
SELECT *,
DATE_FORMAT((STR_TO_DATE(CONCAT(LEFT(CURRENT_DATE, 8), Weekday), '%X-%V-%W') + INTERVAL 1 DAY), '%a'),
'00:00', Endtime
FROM user_time
WHERE Starttime > Endtime
)
SELECT No, Restaurant, Weekday, Starttime, Endtime
FROM cte
WHERE day = DATE_FORMAT(CURRENT_DATE, '%a')
AND NOW() BETWEEN CONCAT(CURRENT_DATE, ' ', time1, ':00') AND CONCAT(CURRENT_DATE, ' ', time2, ':00')
デモ
をご覧ください。 。