This Leetcode problem Managers with at Least 5 Direct Reports LeetCode Solution is done in SQL.
List of all LeetCode Solution
![Managers with at Least 5 Direct Reports LeetCode Solution](https://i0.wp.com/totheinnovation.com/wp-content/uploads/2024/02/LeetCode-Problem-Solution.png?resize=200%2C200&ssl=1)
Managers with at Least 5 Direct Reports LeetCode Solution
Table of Contents
Problem Statement
Column Name | Type |
id | int |
name | varchar |
department | varchar |
managerId | int |
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:
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 |
Output:
name |
John |
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
);
Code language: SQL (Structured Query Language) (sql)