더북(TheBook)

다른 예제를 봅시다.

코드 11-29

CREATE OR REPLACE VIEW dept_sal_v AS
WITH tmp AS
(SELECT a.dept_no, a.dept_name, COUNT(*) cnt, SUM(c.salary) salary
   FROM departments a, dept_emp_v b, salaries c
  WHERE a.dept_no = b.dept_no
    AND b.emp_no = c.emp_no
    AND SYSDATE() BETWEEN c.from_date AND c.to_date
  GROUP BY a.dept_no, a.dept_name
),
dept_avg AS
(SELECT AVG(salary) avg_sal
   FROM tmp
)
SELECT dept_no, dept_name, salary, avg_sal
  FROM tmp, dept_avg;

SELECT *
  FROM dept_sal_v;

실행결과

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.