코드 :
--오늘의 자습시간 문제_2026_01_26
--문제1. 아래의 not exists 문을 minus 로 수행하시오 (이수자 평가 제출물 7번)
--변경 전
SELECT COUNT(*)
FROM orders o
WHERE not exists (
SELECT /*+ nl_sj index(m idx_members_city_id) */ 1
FROM members m
where m.member_id = o.member_id
and city = 'Busan'
);
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
--7979
--변경 후
SELECT COUNT(*)
FROM orders
WHERE member_id IN (
SELECT member_id
FROM orders
MINUS
SELECT member_id
FROM members
WHERE city = 'Busan'
);
--7979
코드 :
--문제2. 아래의 SQL을 grouping sets 로 변경하시오
--변경 전
select job, deptno, null as mgr, sum(sal)
from emp
group by job, deptno
union all
select null as job, deptno, mgr, sum(sal)
from emp
group by deptno, mgr
union all
select null as job, null as deptno, null as mgr, sum(sal)
from emp
order by job, deptno;
--변경 후
select job, deptno, mgr, sum(sal)
from emp
group by grouping sets((job,deptno),(deptno,mgr),())
order by 1,2,3,4;
코드 :
--문제3. 아래의 SQL을 해쉬 세미 right anti 조인으로 수행하시오
--(실행계획을 제출하세요)
--변경 전
select *
from telecom_table
where telecom not in ( select telecom
from dba22 );
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
--변경 후
select *
from telecom_table t
where telecom not in ( select /*+unnest hash_aj swap_join_inputs(d)*/ telecom
from dba22 d
where d.telecom is not null)
and t.telecom is not null;
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));