Click here to see the full article post
Using Subquery is faster.
SELECT Name FROM Employee WHERE Employee.Id IN (SELECT ManagerId FROM Employee GROUP BY ManagerId HAVING COUNT(ManagerId) >= 5) ;
select Name from Employee Where Id IN (select ManagerId from Employee e2 GROUP BY e2.ManagerId HAVING count(ManagerId) > 4);```
SELECT Name FROM Employee e1 WHERE EXISTS ( SELECT 'x' FROM Employee e2 WHERE e2.managerid = e1.id GROUP BY e2.managerid HAVING count(e2.id) >= 5 )
SELECT e.Name FROM Employee e JOIN (SELECT ManagerId, COUNT(*) FROM Employee GROUP BY ManagerID HAVING COUNT(*) >= 5) AS m ON e.Id = m.ManagerID ;
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.