I have an Employee table with columns : Id, Name, Manager_Name
I need to list: count of employees under each manager.
How to form a simple sql query for achieving result?
Note: There may be two managers with same name.
Table:- create table employee_test (Id int , Name VARCHAR(100), Manager_Name varchar(100));
Input:
ID NAME MANAGER_NAME
-- ------ ------------
1 deep hari
2 mitra hari
3 hari kishan
4 kirti kishan
5 kishan amit
6 jumeet hari
7 fareed deep
8 stuti kishore
My Attempt:-
SELECT m.Name as ManagerName, count(e.Name) as employeesCount FROM employee_test e INNER JOIN employee_test m ON e.Manager_Name = m.Name group by m.Name
My Output:-
MANAGERNAME EMPLOYEESCOUNT
----------- --------------
kishan 2
hari 3
deep 1
But it does not take care of other manager's employee count?
UPDATE:- Question was little unclear to me too as being exactly asked by an interviewer, request to close the question.