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
相关推荐
꒰ঌ 安卓开发໒꒱3 分钟前
Go高并发在企业级项目中的实战应用:数据库访问与GIN+GORM深度实践
数据库·golang·gin
半夏知半秋13 分钟前
mongodb的复制集整理
服务器·开发语言·数据库·后端·学习·mongodb
程序员柳39 分钟前
基于深度学习技术实现染色质开放区域的预测与分析系统源代码+数据库,采用Flask + Vue3 实现前后端分离的植物染色质可及性预测系统
数据库·深度学习·flask
苦学编程的谢1 小时前
Redis_3_Redis介绍+常见命令
数据库·redis·github
JavaEdge.1 小时前
榨干 CPU 性能:通过绑核将 Redis 尾延迟减半!
数据库·redis·缓存
YDS8291 小时前
Redis入门 —— 基本数据类型和Spring Data Redis
数据库·redis·spring
一个儒雅随和的男子1 小时前
Redis大Key调优指针
数据库·redis·缓存
IT 小阿姨(数据库)1 小时前
PostgreSQL pg_stat_bgwriter 视图各个字段详解
linux·数据库·sql·postgresql·centos
王卫东3 小时前
深入HBase:原理剖析与优化实战
大数据·数据库·hbase
呆呆小金人3 小时前
SQL键类型详解:超键到外键全解析
大数据·数据库·数据仓库·sql·数据库开发·etl·etl工程师