with opwc (num, ws) AS ( -- обычный
Select 1 num, '02' ws from dual
union all
Select 2 , '02' from dual
union all
Select 3 , '01' from dual
union all
Select 4 , '01' from dual
union all
Select 5 , '03' from dual
union all
Select 6 , '01' from dual
union all
Select 7 , '01' from dual
union all
Select 8 , '04' from dual
union all
Select 9 , '01' from dual
union all
Select 10 , '01' from dual
)
Select num, ws, DENSE_RANK() OVER (PARTITION BY ws ORDER BY numgroup) Seq
from (Select num, ws, case when lag(ws, 1,1) over (order by num) = ws then num-1 else num end numgroup
from opwc) o
order by num