Managers with at Least 5 Direct Reports LeetCode Solution

Last updated on October 9th, 2024 at 10:43 pm

This Leetcode problem Managers with at Least 5 Direct Reports LeetCode Solution is done in SQL.

List of all LeetCode Solution

Level of Question

Medium

Managers with at Least 5 Direct Reports LeetCode Solution

Managers with at Least 5 Direct Reports LeetCode Solution

Problem Statement

Column NameType
idint
namevarchar
departmentvarchar
managerIdint
Table: Employee

id is the primary key (column with unique values) for this table.
Each row of this table indicates the name of an employee, their department, and the id of their manager.
If managerId is null, then the employee does not have a manager.
No employee will be the manager of themself.

Write a solution to find managers with at least five direct reports.

Return the result table in any order.

The result format is in the following example.

Example 1:
Input:

idnamedepartment managerId
101JohnAnull
102DanA101
103JamesA101
104AmyA101
105AnneA101
106RonB101
Employee table:

Output:

name
John

1. Managers with at Least 5 Direct Reports LeetCode Solution MySQL

select 
  Name 
from 
  Employee 
where 
  Id in (
    select 
      ManagerId 
    from 
      Employee 
    group by 
      ManagerId 
    having 
      count(*) >= 5
  );
Scroll to Top