I have a table called notes, and there I have three fields:
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.
id - field INT
start_time - field TIMESTAMP
duration - This is the INT field, which indicates the number of seconds, how much time each event takes.
I write SQL-query that retrieves 3 fields as input: duration, begin_timeand end_timeand I will return the field timestamp, which can only be new.
Based on a lot of questions, similar to mine, on StackOverflow (basically, this MySQL / PHP is to find the available time intervals ) I created a query:
SELECT (a.start_time + a.duration) AS free_after FROM notes a
WHERE NOT EXISTS ( SELECT 1 FROM notes b
WHERE b.start_time BETWEEN (a.start_time+a.duration) AND
(a.start_time+a.duration) + INTERVAL '$duration' SECOND) AND
(a.start_time+a.duration) BETWEEN '$begin_time' AND '$end_time'
But when I run it like this:
SELECT (a.start_time + a.duration) AS free_after FROM notes a
WHERE NOT EXISTS ( SELECT 1 FROM notes b WHERE b.start_time
BETWEEN (a.start_time+a.duration) AND (a.start_time+a.duration) + INTERVAL 15 SECOND )
AND (a.start_time+a.duration) BETWEEN '2015-11-21 19:41:30' AND '2015-11-21 19:43:50'
, , , , :
free_after
2015-11-21 19:42:20
( :
3 | 2015-10-21 19:42:05 | 15
4 | 2015-10-21 19:42:35 | 15
15 ). , ?
==== EDIT:
show warnings, :
Truncated incorrect DOUBLE value: '2015-11-21 19:4...
Truncated incorrect DOUBLE value: '2015-11-21 19:4...
Truncated incorrect DOUBLE value: '2015-11-21 19:4...
Truncated incorrect DOUBLE value: '2015-11-21 19:4...
Incorrect datetime value: '0'
, , ?
===== 2
, @Richard ( btw!), :
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 ) AND
(a.start_time + INTERVAL a.duration SECOND) BETWEEN '2015-11-21 19:41:30' AND '2015-11-21 19:43:50'
( ):
2015-10-21 19:42:50
( ). 2015-10-21 19:42:20... - , ? show warnings - : (