Let's say that I have a table that looks like this, giving me the times of various events in seconds.
event_time
----------
11
14
18
20
25
39
42
43
50
I am trying to come up with a query that will give me a set of rows from this table, where each row is separated by at least 10 seconds from other rows in the result.
The desired result would be:
event_time
----------
11
25
39
50
The row with event_time=11
is included because there is nothing preceding it. The row with event_time=25
is the next one to be returned, because it is the first row that is at least 10 seconds from the row with event_time=11
.
I am using Postgres. I would be able to do this with a recursive query / CTE, but cannot make that work without using an ORDER BY, LIMIT, etc. clause, and Postgres apparently does not allow these in recursive queries.