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 31 32 33 34
| with
/*
menu (men, prog, code, seq) as (
values
('MENIKOS', 'SPA110DJ', '', 100),
('MENIKOS', '', 'GDC', 200),
('MENIKOS', 'CPP100DJ', '', 300),
('GDC', 'GDC110EJ', '', 100),
('GDC', 'GDC210EJ', '', 200),
('GDC', 'GDC310EJ', '', 300),
('GDC', 'GDC410EJ', '', 400),
('GDC', 'CTC110EJ', '', 500),
('GDC', 'CPP100DJ', '', 600),
('GDC', '', 'ALRTCONG', 700),
('GDC', 'GDC540EJ', '', 800),
('ALRTCONG', 'ALRT101C', '', 10),
('ALRTCONG', 'ALRT102C', '', 20),
('ALRTCONG', 'ALRT103C', '', 30),
('ALRTCONG', 'ALRT104C', '', 40),
('ALRTCONG', 'ALRT105C', '', 50),
('ALRTCONG', 'ALRT106C', '', 60),
('ALRTCONG', 'ALRT107C', '', 70)
),
*/
sans_parent as (
select distinct men from menu where not exists(select 0 from menu parent where parent.code = menu.men)
),
hierarchie (rang, men, prog, code, seq) as (
select 1, men, prog, code, seq from menu inner join sans_parent using(men)
union all
select rang + 1, menu.men, menu.prog, menu.code, menu.seq from hierarchie inner join menu on menu.men = hierarchie.code
)
select * from hierarchie
order by rang, men, seq |
Partager