SELECT type, time_from, time_to
FROM manager_orders
WHERE aptid = 262707
AND cancelled_at is null
AND ('2021-04-26 11:00:00'
BETWEEN time_from - INTERVAL 30 Minute
AND time_to + INTERVAL 30 Minute
OR '2021-04-26 11:00:00'
BETWEEN time_from - INTERVAL 30 Minute
AND time_to + INTERVAL 60 Minute
)
SELECT type, time_from, time_to
FROM manager_orders
WHERE aptid = 262707
AND cancelled_at is null
AND (
time_from <= '2021-12-07 16:12:00' + INTERVAL 30 Minute AND
time_to >= '2021-12-07 16:12:00' - INTERVAL 60 Minute
);