我已经可以获取经理的ID,但是我需要能够获取这三个经理的名字,他们目前被困在那里。

select d.manager_id, count(employee_id)
from hr.departments d
inner join hr.employees e on d.department_id = e.department_id
group by d.manager_id
having count(employee_id) > 5

当我试着做的时候
select d.manager_id, e.first_name, e.last_name, count(employee_id)
from hr.departments d
inner join hr.employees e on d.department_id = e.department_id
group by d.manager_id, e.first_name, e.last_name
having count(employee_id) >5

我得到的结果是空白的

最佳答案

你也必须在joinemployee_id

select d.manager_id, e1.first_name, e1.last_name, count(e.employee_id)
from hr.departments d
inner join hr.employees e on d.department_id = e.department_id
inner join hr.employees e1 on d.manager_id = e1.employee_id
group by d.manager_id, e.first_name, e.last_name
having count(e.employee_id) > 5

关于mysql - ID中需要的经理姓名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33268236/

10-13 00:48