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 27 28 29 30
| select ll1,ll2, ll3, ll4, ll5 from (
select path, nom_racine, nvl2(l1,1, nvl2(l2,2,nvl2(l3,3, nvl2(l4,4,5)))) as lvl, l1, l2, l3, l4, l5 from (
select level as lvl, poste_id,encadrant_poste_id, nom, connect_by_root(nom) as nom_racine,
sys_connect_by_path(nom,'/') as path
from data
start with encadrant_poste_id is null
connect by prior poste_id = encadrant_poste_id
)
pivot (
min(nom) for lvl in (1 as L1,2 as L2,3 as L3,4 as L4,5 as l5)
)
)
match_recognize (
partition by nom_racine
order by path, lvl
measures R1.L1 as LL1,
(case when classifier() >= 'R2' then R2.L2 end) as LL2,
(case when classifier() >= 'R3' then R3.L3 end) as LL3,
(case when classifier() >= 'R4' then R4.L4 end) as LL4,
(case when classifier() >= 'R5' then R5.L5 end) as LL5
all rows per match
after match skip to next row
pattern( R1 (R2|R3|R4|R5)* (R3|R4|R5)* (R4|R5)* R5* )
define
R1 as lvl = 1,
R2 as lvl = 2,
R3 as lvl = 3,
R4 as lvl = 4,
R5 as lvl = 5
) |
Partager