--■■■having句で固定で3を指定する方法■■■
select
max(decode(job,'CLERK' ,ENAME)) as CLERK,
max(decode(job,'SALESMAN',ENAME)) as SALESMAN,
max(decode(job,'MANAGER' ,ENAME)) as MANAGER
from (select ENAME,job,
Row_Number() over(partition by job order by ENAME) as Rn
from scott.emp
where job in('CLERK','SALESMAN','MANAGER'))
group by Rn
having count(*) = 3
order by Rn;
--■■■論理積を判定する方法■■■
select
max(decode(job,'CLERK' ,ENAME)) as CLERK,
max(decode(job,'SALESMAN',ENAME)) as SALESMAN,
max(decode(job,'MANAGER' ,ENAME)) as MANAGER
from (select ENAME,job,
Row_Number() over(partition by job order by ENAME) as Rn
from scott.emp
where job in('CLERK','SALESMAN','MANAGER'))
group by Rn
having max(decode(job,'CLERK' ,ENAME)) is not null
and max(decode(job,'SALESMAN',ENAME)) is not null
and max(decode(job,'MANAGER' ,ENAME)) is not null
order by Rn;