Reputation: 177
Sorry for butchering the question but i didn't know how to word it.
My question is if i have this as my result:
Result http://puu.sh/cdKkz/5bf31b2172.png
How would i be able to replace the manager_id with the managers name?
This is the employees table:
Upvotes: 0
Views: 37
Reputation: 177
Found the answer
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
Upvotes: 0
Reputation: 3091
Try a self join
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
Upvotes: 1