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
相关推荐
小园子的小菜几秒前
MySQL ORDER BY 深度解析:索引排序规则与关键配置参数阈值
数据库·mysql
wxjlkh2 分钟前
Oracle Exadata一体机简介 1千多个W
数据库·oracle
泽虞17 分钟前
《Qt应用开发》笔记p3
linux·开发语言·数据库·c++·笔记·qt·面试
XXYBMOOO21 分钟前
如何自定义 Qt 日志处理并记录日志到文件
开发语言·数据库·qt
不剪发的Tony老师30 分钟前
PEV2:一款PostgreSQL执行计划可视化工具
数据库·postgresql
IT 小阿姨(数据库)30 分钟前
PostgreSQL wal_e 工具详解
运维·数据库·sql·postgresql·centos
有想法的py工程师34 分钟前
AL2系统下编译安装PSQL16.4版本
linux·运维·数据库·postgresql
惊鸿一博37 分钟前
mysql_page pagesize 如何实现游标分页?
数据库·mysql
泽虞1 小时前
《Qt应用开发》笔记p4
linux·开发语言·数据库·c++·笔记·qt·算法
观远数据1 小时前
A Blueberry 签约观远数据,观远BI以一站式现代化驱动服饰企业新增长
大数据·数据库·人工智能·数据分析