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
相关推荐
风哥2号14 小时前
数据库教程FGMT27‑MySQL数据库基础知识与体系架构
数据库·mysql
YangYang9YangYan15 小时前
2026 校招商品分析岗位 JD 拆解,核心指标、工具与面试考点
大数据·数据库·数据分析
西安栈上月明软件科技16 小时前
从业务黑话到本体图谱:OAG本体建模五步法(西安老系统AI化改造实战)
数据库·人工智能·架构
anxiao_m16 小时前
跨云跨机房大数据迁移怎么选?不同场景工具适配指南
数据库·云启快传
风哥2号18 小时前
数据库教程FGMT43‑MySQL性能分析与优化调整
数据库·mysql
随身数智备忘录18 小时前
财务数据分析如何与业务场景结合?财务数据分析如何从数出有据到数出有用?
数据库
这个DBA有点耶20 小时前
数据库教程:从零基础到实战的完整学习路径(2026版)
数据库·程序员·代码规范
forestsea20 小时前
从零构建 Java 智能体 RAG 系统:Milvus 向量数据库实战指南
java·数据库·milvus
默 语20 小时前
Java新手入门:从零开始安装JDK并配置环境变量
java·开发语言·python·mysql·group by·1024程序员节·数据去重
probex_21 小时前
从 ByConity 到 VictoriaMetrics:一次指标数据迁移引发的四种存储对比
数据库