很抱歉诅咒这个问题,但我不知道如何说出来。
我的问题是,如果我将此作为我的结果:
Result http://puu.sh/cdKkz/5bf31b2172.png
我如何能够用经理名称替换manager_id?
这是员工表:
答案 0 :(得分:1)
尝试自我加入
select
e2.employee_id,
e2.first_name,
e2.last_name,
count(e1.employee_id) as employees
from
employees e1
inner join
employees e2 ON e1.manger_id=e2.employee_id and e1.manager_id <> 0
group by e2.employee_id,
e2.first_name,
e2.last_name
答案 1 :(得分:0)
找到答案
select ie.first_name + ' ' + ie.last_name as 'manager_name', count(ie.employee_id) as 'employees'
from employees e inner join employees ie on e.manager_id = ie.employee_id
group by ie.first_name + ' ' + ie.last_name