答案 0 :(得分:0)
如果要列出员工和每个员工的部门经理的姓名,您需要两次加入Employee表。一种方法是:
Select Employees.*
, Departments.*
, Managers.EmployeeName as ManagerName
From Employees
Inner Join Departments on departments.DeptID = employees.DeptID
Inner Join Employees managers on managers.EmpId = departments.ManagerID
答案 1 :(得分:0)
除了你需要更多地解决问题之外......
如果您要做的就是找到经理......您只需要使用经理ID将部门加入员工......就像这样
select
e.empid
,e.empname
,e.jobtitle
,e.salary
,d.deptname
,m.empname as manager_name
from employee e
inner join departments d
on d.deptid = e.deptid
left join employee m
on m.empid = d.managerid