(employee_id, manager_id, reporting_level, first_name, last_name, salary, title) as
(select employee_id, manager_id, 0 reporting_level, first_name, last_name, salary, the title from more_employees
Union all
The select e.e mployee_id, e.m anager_id, r.r eporting_level + 1 as reporting_level, e.f irst_name, e.l ast_name, e.s alary, e. itle
The from reporting_hierarchy r, more_employees e
Where r.e mployee_id=e.m anager_id
)
Search the depth first by employee_id set order_by_employee_id
Cycle title set same_title to 'Y' default 'N'
Select employee_id, manager_id, lpad (', 2 * reporting_level) | | first_name | | "| | last_name as employee, salary and title, same_title
The from reporting_hierarchy
The order by order_by_employee_id;
In the where clause, r.e mployee_id=e.m anager_id and e.e mployee_id=r.m anager_id swaps, what's the difference? What is action?
CodePudding user response:
in the where clause, r.e mployee_id=e.m anager_id and e.e mployee_id=r.m anager_id swaps have what differentiation? What is action?Without your structure, from the point of view on the statement:
The former is upward query, yourself - & gt; His superiors - & gt; The superior superior
The latter is the query down, his - & gt; His underlings - & gt; Subordinate staff,
CodePudding user response:
The table, this is my more_employees I practice is to use recursive subquery factor query hierarchical data, including r.e mployee_id=e.m anager_id and e.e mployee_id=r.m anager_id this two equations for the two different coding, switch when I r. and e., their output will have difference, don't understand their logical order, if the difference of the difference of the output?
CodePudding user response:
If it is recursive, of course, there are differences, the difference between the recursive traversal and up downCodePudding user response:
R.e mployee_id=e.m anager_id if this equation, it should be r.e mployee_id, then enter the e.m traverse anager_id?