我有2张表格如下
employees(id int,name varchar(20),salary int);
employee_manager(eid int,mid int);
我希望得到结果
ID,NAME,Manager_Name
我只能获取Manager_Name的ID,如何获得结果。
查询获取姓名,员工ID,经理ID(员工ID)
select e.name, e.id, NVL(m.mid, 'NONE') AS Manager_ID
from employees e
left join EMPLOYEE_MANAGER m ON e.id = m.eid;
查询选择作为经理的员工姓名。
select distinct e.name
from employees e, EMPLOYEE_MANAGER m
where m.mid = e.id;
答案 0 :(得分:0)
您可以通过在连接employee_manager
和employees
的派生表上保持联接来获取经理信息来执行此操作:
select e.id, e.name, nvl(m.name, 'NONE') as manager_name
from employees e
left join (
select em.eid, m.name
from employee_manager em
join employees m
on m.id = em.mid
) m on m.eid = e.id