最も単純なオプションは、一般的に次のようなものです
SQL> ed
Wrote file afiedt.buf
1 with x as (
2 select 1 id, 1 val from dual union all
3 select 1 id, 2 val from dual union all
4 select 1 id, 3 val from dual union all
5 select 2 id, 1 val from dual union all
6 select 2 id, 2 val from dual union all
7 select 3 id, 1 val from dual union all
8 select 3 id, 2 val from dual union all
9 select 3 id, 3 val from dual union all
10 select 4 id, 1 val from dual
11 )
12 select id
13 from x
14 where val in (1,2,3)
15 group by id
16* having count(distinct val) = 3
SQL> /
ID
----------
1
3
WHERE 句は、関心のある値を識別します。HAVING 句は、これらの値がいくつ存在する必要があるかを示します。たとえば、3つの値のうち少なくとも2つを持つすべての行が必要な場合は、HAVINGを変更します。 COUNTを検索する句 の2。
特定のvalの場合 idごとに最大1回発生することが保証されています 、distinctを削除できます HAVINGで 句。