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
相关推荐
一米阳光86614 小时前
软考(中级)软件设计师核心笔记(3)数据库系统——概念、数据库设计
数据库·笔记·职场发展·软考·软件设计师
奈斯先生Vector5 小时前
告别工具碎片化:基于 Nano Banana 全模态 AI 聚合架构搭建“文本-图像-视频”自动化协同生产线
运维·数据库·人工智能·架构·自动化·aigc·音视频
建筑工程企业管理系统6 小时前
erp工程项目管理系统落地价值:实现工程多项目成本精细化核算与管控
大数据·数据库·人工智能
AI大模型-小华7 小时前
Codex 三方充值快速入门指南
java·前端·数据库·chatgpt·ai编程·codex·chatgpt pro
foolishlee8 小时前
Neon wal日志处理流程2
数据库
2601_965798478 小时前
Is Hygia Good for Maid & Janitorial Sites? Technical Audit
服务器·网络·数据库
Cloud云卷云舒9 小时前
海山数据库(HaishanDB)面向工业云场景技术方案
数据库·haishandb·工业云·移动云海山数据库·天工云
逃逸线LOF9 小时前
Spring配置数据源{连接池}(Druid、c3p0)
java·数据库·spring
☆凡尘清心☆11 小时前
CentOS Stream 9 专用 LNMP 全自动一键脚本
linux·运维·mysql·nginx·lnmp·centos stream 9
严同学正在努力11 小时前
从备份到恢复:我用 30 分钟恢复了误删的核心业务表
android·java·数据库·ai