1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| WITH
Repere AS (SELECT 'Rep1' Nom FROM DUAL union all select 'Rep2' FROM DUAL),
Article as (select 'Rep1' rep, 'Art1' Nom from dual union all select 'Rep1' rep, 'Art2' Nom from dual
union all select 'Rep2', 'Art5' from dual),
Mp as (select 'Art1' art, 'MP1' Nom from dual union all select 'Art1' art, 'MP2' Nom from dual
union all select 'Art1' art, 'MP3' Nom from dual union all select 'Art1' art, 'MP4' Nom from dual
union all select 'Art2' art, 'MP1' Nom from dual union all select 'Art2' art, 'MP2' Nom from dual
union all select 'Art2' art, 'MP3' Nom from dual union all select 'Art5', 'MP1' from dual)
SELECT sel.Nom,
Mp.Nom as Mp
FROM
(
SELECT Repere.Nom,
Article.Nom AS Art,
COUNT(1) over(partition by Repere.Nom ) AS n_art
FROM Repere
JOIN Article ON Article.Rep = Repere.Nom
) sel JOIN Mp ON Mp.art = sel.Art
GROUP BY sel.Nom, Mp.Nom, n_art
HAVING count(1) = n_art |
Partager