570. Managers with at Least 5 Direct Reports 至少有5个直接汇报员工的经理
The Employee
table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
+------+----------+-----------+----------+
|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 |
+------+----------+-----------+----------+
Given the Employee
table, write a SQL query that finds out managers with at least 5 direct report. For the above table, your SQL query should return:
+-------+
| Name |
+-------+
| John |
+-------+
Note:
No one would report to himself.
给一个员工表和一个经理表,员工表里有经理id列,查询出所有至少有5个直接汇报员工的经理。
解法1:
SELECT
Name
FROM
Employee AS t1 JOIN
(SELECT
ManagerId
FROM
Employee
GROUP BY ManagerId
HAVING COUNT(ManagerId) >= 5) AS t2
ON t1.Id = t2.ManagerId
;
解法2:
with cte as(
select ManagerId from employee
group by ManagerId
having count(Id)>=5
) select Name from employee e join cte c on e.Id=c.ManagerId
All LeetCode Questions List 题目汇总
570. Managers with at Least 5 Direct Reports 至少有5个直接汇报员工的经理的更多相关文章
- SQL练习——LeetCode解题和总结(1)
只用于个人的学习和总结. 178. Rank Scores 一.表信息 二.题目信息 对上表中的成绩由高到低排序,并列出排名.当两个人获得相同分数时,取并列名次,且名词中无断档. Write a SQ ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- Leetcode problems classified by company 题目按公司分类(Last updated: October 2, 2017)
All LeetCode Questions List 题目汇总 Sorted by frequency of problems that appear in real interviews. Las ...
- 【sql】leetcode习题 (共 42 题)
[175]Combine Two Tables (2018年11月23日,开始集中review基础) Table: Person +-------------+---------+ | Column ...
- Sql practice
employee表 数据准备 use tempdb go if OBJECT_ID('employee') is not null drop table employee ;with employee ...
- Understanding and Using HRMS Security in Oracle HRMS
Understanding and Using HRMS Security in Oracle HRMS Product:Oracle Human Resources Minimum Version: ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) F dfs序+树状数组
Performance ReviewEmployee performance reviews are a necessary evil in any company. In a performance ...
- Object Modeling
https://developer.apple.com/library/content/documentation/General/Conceptual/CocoaEncyclopedia/Objec ...
- [他山之石]Google's Project Oxygen Pumps Fresh Air Into Management
The Project Oxygen team spent one year data-mining performance appraisals, employee surveys, nominat ...
随机推荐
- CentOS7:sorry,that didn't work.please try again!
参考以下解决方案,重点是vi etc/selinux/config 把 enforcing 改为 disable 应用场景 linux管理员忘记root密码,需要进行找回操作.注意事项:本文基于cen ...
- es6 字符串模板拼接和传统字符串拼接
字符串拼接是在日常开发中必不可少的一个环节. 注意:字符串可以用单引号'',或者""双引号,出于方便大家理解,文章以下内容统一使用单引号''! 如果只是一个字符串和一个变量拼接,使 ...
- springboot的第一节课
快速开始spring boot应用 官方向导搭建boot应用 地址:http://start.spring.io/ 设置项目属性: 3.解压,拷贝到工作空间,导入maven项目 4.写Controll ...
- 《基于WEB的独立学院补考重修管理系统研究》论文笔记(二十)
<基于WEB的独立学院补考重修管理系统研究>论文笔记(1) 一.基本信息 标题:基于WEB的独立学院补考重修管理系统研究 时间:2016 来源:南通大学杏林学院 关键词:WEB:补考重修管 ...
- 解决最新版fitnesse无法运行测试用例的问题
用fitnesse-standalone.jar这个jar包时 运行测试用例会报错,显示IOException:can not run program:”c:\program files\java\j ...
- Vigil 发送多人邮件通知的处理
Vigil 默认是只能发送单人邮件,但是我们有需要发送多个的场景. 解决方法: 大家使用一样的账户登陆 使用邮件组 修改下源码 为了学习下Vigil 的构建,以及原理,我简单通过修改源码的方式(目前支 ...
- C++之Lambda研究
目录 目录 1 1. 前言 1 2. 示例1 1 3. 示例2 2 4. 示例3 3 5. 示例4 3 6. 示例5 6 7. 匿名类规则 6 8. 参考资料 7 1. 前言 本文代码测试环境为“GC ...
- luoguP3003 [USACO10DEC]苹果交货Apple Delivery
LOL新英雄卡莎点击就送 一句话题意: 三个点a1,a2,b,求从b到a1和a2的最短路 做法:求出a1->b和a2->b的最短路,两者取min,之后再加上a1->a2的最短路 为啥 ...
- 干货 | 10分钟教你用column generation求解vehicle routing problems
OUTLINE 前言 VRPTW description column generation Illustration code reference 00 前言 此前向大家介绍了列生成算法的详细过程, ...
- 转载:Databricks孟祥瑞:ALS 在 Spark MLlib 中的实现
Databricks孟祥瑞:ALS 在 Spark MLlib 中的实现 发表于2015-05-07 21:58| 10255次阅读| 来源<程序员>电子刊| 9 条评论| 作者孟祥瑞 大 ...