1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| WITH MaTable AS
(
select 200 as indiv, 'pole' as libl, 1212 as ident, 'rue' as adres from dual union all
select 200 , null , 3 , 'rue' from dual union all
select 555 , null , null , 'impasse' from dual union all
select 555 , null , 221 , 'impasse' from dual union all
select 655 , 'pole' , null , 'impasse' from dual
)
select indiv, libl, ident, adres,
row_number() over(partition by indiv order by case libl when 'pole' then 1 else 0 end desc, libl asc, ident asc, adres asc) as rn
from MaTable;
INDIV LIBL IDENT ADRES RN
200 pole 1212 rue 1
200 3 rue 2
555 221 impasse 1
555 impasse 2
655 pole impasse 1 |
Partager