Database/Oracle
ORACLE|WITH 구문
어느가을빛
2011. 7. 25. 10:29
WITH 절
- 같은 쿼리 블럭이 두 번 이상 반복해서 사용된다면 위드 절을 이용해 가독과 편의성을 높일 수 있다.
- 쿼리 블록의 결과를 추출해서 유저의 임시 테이블 스페이스에 저장한다.
- 성능 향상
with
dept_costs as ( select d.department_name, sum(e.salary) as dept_total
from employees e join department d
on e.department_id = d.department_id
group by d.department_name),
avg_cost as( select sum(dept(total)/count(*) as dept_avg
from dept_costs)
select *
from depts_costs
where dept_total > (select dept avg
from avg_costs)
order bt department_name;
-> 두 개의 서브 쿼리를 dept_cost와 avg_cost라는 테이블 처럼 사용하고 있다.
with 별칭 as (서브쿼리) 메인쿼리
#출처 : http://devideby0.egloos.com/2078222