Managers with at least 5 direct reports

  • 0

    Given an employee table, find all managers with at least 5 direct reports.

    Id Name Department ManagerId
    101 John A null
    102 Dan A 101
    103 James A 101
    104 Amy A 101
    105 Anne A 101
    106 Ron B 101

    For the above table, your SQL query should return "John".

  • 1

    SELECT Name FROM Employee AS e INNER JOIN (SELECT ManagerId as m, COUNT(id) as c FROM Employee GROUP BY ManagerId HAVING c>=5) as e2
    ON = e2.m

  • 3
    select name from employee where id = (select managerid from employee group by managerid having count(managerid) >=5)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.