Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table events(id serial primary key, start_time timestamp);
- insert into events (start_time) values
- ('2017-11-10 12:00'),
- ('2017-11-10 12:32'),
- ('2017-11-10 12:39'),
- ('2017-11-10 12:42'),
- ('2017-11-10 13:55'),
- ('2017-11-10 14:19');
- select id as window_start, next_id as window_end, time_window
- from (
- select
- id, start_time,
- lead(start_time) over w - start_time as time_window,
- lead(id) over w as next_id
- from events
- window w as (order by start_time)
- ) e
- where time_window >= '0:30';
- window_start | window_end | time_window
- --------------+------------+-------------
- 1 | 2 | 00:32:00
- 4 | 5 | 01:13:00
- (2 rows)
Add Comment
Please, Sign In to add comment