You can do this by creating a sequence of numbers and subtracting from step . This will be constant when the values ββare sequential:
select min(step) as from_step, max(step) as to_step, data from (select t.*, row_number() over (partition by data order by step) as seqnum from t ) t group by (step - seqnum), data;
EDIT:
It's not clear where NULL comes from. If I assume 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, data from (select t.*, max(step) over (partition by data) as max_step row_number() over (partition by data order by step) as seqnum from t ) t group by (step - seqnum), data, max_step;
Gordon linoff
source share