어느 가을날의 전환점
ORACLE|WITH 구문 본문
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
'Database > Oracle' 카테고리의 다른 글
| ORACLE|권한(Grant) 자동화 (0) | 2011.08.05 |
|---|---|
| ORACLE|Oracle Instant Client (0) | 2011.08.03 |
| ORACLE|Oracle10g - CONNECT_BY_ROOT, SYS_CONNECT_BY_PATH, CONNECT_BY_ISLEAF (0) | 2011.07.25 |
| ORACLE|LEAD(), LAG() 함수 - 특정 컬럼의 지정한 숫자 다음/이전행 데이터 리턴. (0) | 2011.07.25 |
| ORACLE|자율 트랜잭션(Autonomous Transaction) - 채번 시 활용 (0) | 2011.07.25 |
Comments