This is a continuation of my previous question. Request to search for the closest free time interval in mysql - why does it not work?
Basically, I have a table:
id | start_time | duration
1 | 2015-10-21 19:41:35 | 15
2 | 2015-10-21 19:41:50 | 15
3 | 2015-10-21 19:42:05 | 15
4 | 2015-10-21 19:42:35 | 15
etc.
and contains the start_time event and its duration. I asked for help finding the closest time interval in which an event can be placed between existing events. @Richard came up with a great answer to https://stackoverflow.com/a/166649/ and suggested a query:
SELECT (a.start_time + INTERVAL a.duration SECOND) AS free_after FROM notes a
WHERE
NOT EXISTS ( SELECT 1 FROM notes b WHERE b.start_time
BETWEEN (a.start_time + INTERVAL a.duration SECOND) AND
(a.start_time + INTERVAL a.duration SECOND) + INTERVAL 15 SECOND - INTERVAL 1 MICROSECOND) AND
(a.start_time + INTERVAL a.duration SECOND) BETWEEN '2015-10-21 19:41:30' AND '2015-10-21 19:43:50'
which works great.
Now I was wondering if it was possible to find a suitable date not only between existing dates, but also immediately before them.
: begin_date 2015-10-21 16:00:00 end_date 2015-10-21 21:00:00. @Richard 2015-10-21 19:42:20. , 2015-10-21 19:41:20 , ?