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
相关推荐
正儿八经的少年16 分钟前
布隆过滤器(解决redis缓存穿透步骤之一)
数据库·redis·缓存
xrandzj44 分钟前
MySQL8.0 从零通关核心操作手册(Ubuntu实战版)
数据库·mysql
我不会插花弄玉1 小时前
4.数据类型【由浅入深-MySQL】
数据库·mysql
denggun123451 小时前
yield
前端·数据库·python
ltl1 小时前
SQLite Rollback Journal:写前拷贝与提交点
数据库
ltl1 小时前
TiFlash Learner:Raft 日志如何进列存
数据库
ltl2 小时前
BM25 与 Lucene Similarity:公式如何落到 postings
数据库
ltl2 小时前
RocksDB Block Cache 与 Bloom Filter:读放大怎么裁
数据库
deli0070073 小时前
JSON 树形查看器:粘贴即解析,折叠展开一目了然
前端·数据库·json·ai编程
国科安芯3 小时前
轨道供电韧性:ASP4644四通道降压架构在低轨卫星平台电源管理中的适用性分析
运维·网络·数据库·嵌入式硬件·架构·状态模式·低轨卫星星座