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
相关推荐
高级程序源4 分钟前
springboot荆州旅游推介平台24175-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·django·课程设计
wdfk_prog15 分钟前
LWIP教程 10:从 `tcp_receive()` 到 `ooseq` / SACK——TCP 乱序、重组与选择确认
网络·数据库·tcp/ip
狼与自由16 分钟前
Mysql 3种日志的区别
数据库·mysql
linweidong22 分钟前
Redis 集群故障排查与修复实战:从 Connection refused 到内存打满的七个现场
运维·数据库·redis·缓存·redis集群·运维面经·实施面经
StackTraces28 分钟前
从零跑通 Meilisearch 本地搜索服务:6 步,外加 4 个容易卡住的地方
数据库·后端
CoLiuRs31 分钟前
订单不是一张表:订单聚合与状态机
数据库·架构
小米里的大麦31 分钟前
19 C、C++ 操作 MySQL
c语言·c++·mysql
shuoshuohaohao34 分钟前
Spring-boot-3 -注解 yaml配置 -日志
java·数据库·mysql
IT邦德1 小时前
Bond-DBCheck 邦德智能巡检平台助力 DBA
数据库·dba