S
S
Sergey2016-06-03 00:53:26
MySQL
Sergey, 2016-06-03 00:53:26

How to write a sql query to select dates with an interval?

There is a plate with dates in the format "2016-06-03 00:45:00" how to correctly compose a sql query to select all records between which the time interval is more than 15 minutes?
That is, if there are 3 records in the database:
2016-06-03 00:10:00
2016-06-03 00:20:00
2016-06-03 00:40:00
then it should output:
2016-06-03 00:20 :00
2016-06-03 00:40:00

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2016-06-03
@res2001

The general scheme is something like this:

select A.DATE 
from table
join (select A.DATE as DATE, A1.DATE as DATE1
from table A
join table A1 on A1.DATE > date_add(minute, A.DATE, 15)
) A1 on A1.DATE=A.DATE or A1.DATE1=A.DATE

But, most likely, it is necessary to hang additional conditions, because. if there are more than 3 records in the table, then the result may surprise you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question