Oracle - grouping values along interval
You can do this by generating a sequence of numbers and subtracting from the step
. This will be a constant when the values are sequential:
select min(step) as from_step, max(step) as to_step, datafrom (select t.*, row_number() over (partition by data order by step) as seqnum from t ) tgroup by (step - seqnum), data;
EDIT:
It is not quite clear where the NULL
s are coming from. If I speculate that they are the last values for each value, you can do:
select min(step) as from_step, (case when max(step) <> max_step then max(step) end) as to_step, datafrom (select t.*, max(step) over (partition by data) as max_step row_number() over (partition by data order by step) as seqnum from t ) tgroup by (step - seqnum), data, max_step;