I have a table that contains the start time (using the number in the example to keep it simple) and the duration of the events.
I would like to define the “blocks” and their beginning and end.
Whenever the difference between the end time (start time + duration) of the previous line (sorted by start time) and the start time of the current line is equal >=5, a new “block” must begin.
This is my test data, including an attempt at a graphical explanation in the comments:
WITH test_data AS (
SELECT 0 s, 2 dur FROM dual UNION ALL
SELECT 2 , 2 FROM dual UNION ALL
SELECT 10 , 1 FROM dual UNION ALL
SELECT 13 , 4 FROM dual UNION ALL
SELECT 15 , 4 FROM dual
)
The first block starts with 0and ends with 4. Since the difference in the next line is equal >=5, run another block in 10, which ends with 19.
, LAG, , .
PL/SQL-, .
?
,