Can anyone help me to show the second table from the first table in Mysql. I cannot understand how to approach the problem. I know the concept of left join and order by, but still cannot figure it out.
BTREE
Input Table:
Desired Output:
Can anyone help me to show the second table from the first table in Mysql. I cannot understand how to approach the problem. I know the concept of left join and order by, but still cannot figure it out.
BTREE
Input Table:
Desired Output:
Use recursive CTE:
with recursive managers as (
select EmployeeId, name as 'Employee', 'Super Boss' as 'Manager', 1 as Level, ManagerId
from employees
where ManagerId is null
union
select e.EmployeeId, e.name, m.Employee, Level+1, e.ManagerId
from employees e
join managers m on m.EmployeeId=e.ManagerId
)
select Employee, Manager, Level
from managers