Leecode_SQL50_570. Managers with at Least 5 Direct Reports

Leecode

  1. Managers with at Least 5 Direct Reports

Problem description

Table: Employee

±------------±--------+

| Column Name | Type |

±------------±--------+

| id | int |

| name | varchar |

| department | varchar |

| managerId | int |

±------------±--------+

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:

Employee table:

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

My solution

sql 复制代码
WITH a AS(
    SELECT m.name, COUNT(e.managerId) AS coun
    FROM Employee e
        JOIN Employee m
            ON e.managerId = m.id
    GROUP BY e.managerId
)
SELECT a.name
FROM a
WHERE coun >= 5
相关推荐
2301_8038756111 分钟前
如何用 objectStore.get 根据主键 ID 获取数据库单条数据
jvm·数据库·python
weixin_4585801221 分钟前
如何修改AWR保留时间_将默认8天保留期延长至30天的设置
jvm·数据库·python
qq_6543669835 分钟前
C#怎么实现OAuth2.0授权_C#如何对接第三方快捷登录【核心】
jvm·数据库·python
justjinji39 分钟前
如何用 CSS 变量配合 JS setProperty 实现动态换肤功能
jvm·数据库·python
2301_803875611 小时前
C#怎么使用TopLevel顶级语句 C#顶级语句怎么写如何省略Main方法简化控制台程序【语法】
jvm·数据库·python
九皇叔叔1 小时前
MySQL 8.0 测试库安装
数据库·mysql
baidu_340998821 小时前
SQL多维度数据聚合技巧_利用GROUP BY WITH ROLLUP实现
jvm·数据库·python
m0_743623921 小时前
Python如何计算NumPy数组的协方差矩阵_调用cov函数进行特征分析
jvm·数据库·python
qq_380619161 小时前
Layui表格怎么隐藏指定列
jvm·数据库·python
21439651 小时前
mysql如何通过yum源快速安装_mysql官方yum安装教程
jvm·数据库·python