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
相关推荐
运维小子6 分钟前
JumpServer Applet 发布自定义远程应用:Oracle SQL Developer 自动登录
数据库·sql·oracle·jumpserver
m0_5967490910 分钟前
Golang怎么实现方法集与接口的匹配_Golang如何理解值类型和指针类型实现接口的区别【详解】
jvm·数据库·python
学习 来了来了17 分钟前
权限相关代码-表
数据库
薪火铺子19 分钟前
MySQL 分库分表实战:ShardingSphere 深度解析
数据库·mysql
lifewange23 分钟前
查询【学过 001 号同学所有课程】的学生
数据库
ErizJ32 分钟前
Redis|腾讯面经总结
数据库·redis
瀚高PG实验室1 小时前
left link changed unexpectedly in block xxxx of index ““index_xxxxx“
数据库·postgresql·瀚高数据库
一只幸运猫.1 小时前
核心概念层——深入理解 Agent 是什么
大数据·数据库·人工智能
川石课堂软件测试1 小时前
软件测试|常见面试题整理
数据库·python·jmeter·mysql·appium·postman·prometheus
●VON1 小时前
小米突然发短信:送你100万亿Token!有人已收到,有人还没?手把手教你白嫖
数据库·人工智能·skills