Guest User

Untitled

a guest
Nov 20th, 2017
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. create table events(id serial primary key, start_time timestamp);
  2. insert into events (start_time) values
  3. ('2017-11-10 12:00'),
  4. ('2017-11-10 12:32'),
  5. ('2017-11-10 12:39'),
  6. ('2017-11-10 12:42'),
  7. ('2017-11-10 13:55'),
  8. ('2017-11-10 14:19');
  9.  
  10. select id as window_start, next_id as window_end, time_window
  11. from (
  12. select
  13. id, start_time,
  14. lead(start_time) over w - start_time as time_window,
  15. lead(id) over w as next_id
  16. from events
  17. window w as (order by start_time)
  18. ) e
  19. where time_window >= '0:30';
  20.  
  21. window_start | window_end | time_window
  22. --------------+------------+-------------
  23. 1 | 2 | 00:32:00
  24. 4 | 5 | 01:13:00
  25. (2 rows)
Add Comment
Please, Sign In to add comment