<EMPLOYEES>
EMPLOYEE_ID | LAST_NAME | MANAGER_ID | SALARY |
100 | King | 24000 | |
101 | Kochhar | 100 | 17000 |
102 | De Haan | 100 | 17000 |
103 | Hunold | 102 | 9000 |
104 | Ernst | 103 | 6000 |
105 | Austin | 103 | 4800 |
106 | Pataballa | 103 | 4800 |
107 | Lorentz | 103 | 4200 |
108 | Grennberg | 101 | 12000 |
109 | Faviet | 108 | 9000 |
<SQL>
WITH WITH_TAB(last_name, EMP_ID, MGR_ID, sum_salary) as ( select last_name, employee_id, manager_id, salary from employees where manager_id is null union all select a.last_name, a.employee_id, a.manager_id, a.salar+b.sum_salary from employees a, with_tab b where b.emp_id = a.manager_id ) select sum_salary from with_tab where emp_id = 105;
<결과> 54800
WITH_TAB 선언부부터 이해가 잘 가지 않습니다. 아직 정의되지 않은 WITH_TAB 선언부 내부에서 다시 WITH TAB 선언부를 조인한다는 부분이 어려운 것 같습니다.
자세하게 동작 원리를 조금 알려주실 수 있을까요?..