Given an Employee table with following structure
EmpId | EmpName | Department | ManagerId |
---|
Part 1: Write a sql to retrieve all Manager’s Name with 5 or more subordinates.
Note : ManagerId is also an Employee Id.
select EmpName from Employee where EmpId IN (select ManagerId from Employee Group by ManagerId Having count(EmpName)>=5);
Part 2 : Write a sql to retrieve ManagerId who have 5 or more subordinates in one column and comma separated subordinates names in other column .
select ManagerId,group_concat(EmpName) From Employee Group by ManagerId Having count(EmpName)>=5