1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| WITH MaTable AS
(
select 126 as id, 1 as ver, 'ESP' as typ from dual union all
select 126 , 2 , 'ESP' from dual union all
select 126 , 3 , 'USL' from dual union all
select 127 , 1 , 'ESP' from dual union all
select 127 , 2 , 'ESP' from dual union all
select 127 , 3 , 'EPP' from dual union all
select 127 , 4 , 'ESP' from dual union all
select 127 , 5 , 'USL' from dual
)
select id, ver, typ, typ_prev
from
(
select id, ver, typ,
lag(typ, 1, typ) over(partition by id order by ver asc) as typ_prev
from MaTable
)
where typ <> typ_prev
order by id asc, ver asc;
ID VER TYP TYP_PREV
126 3 USL ESP
127 3 EPP ESP
127 4 ESP EPP
127 5 USL ESP |
Partager