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 ...
随机推荐
- django项目中使用手机号登录
本文使用聚合数据的短信接口,需要先获取到申请接口的appkey和模板id 项目目录下创建ubtils文件夹,定义返回随机验证码和调取短信接口的函数 function.py文件 import rando ...
- django-获取购物车商品数量-redis
视图函数views.py中 from django_redis import get_redis_connection # 连接redis class IndexView(View): '''首页'' ...
- RESTful API Design: 13 Best Practices to Make Your Users Happy
RESTful API Design: 13 Best Practices to Make Your Users Happy First step to the RESTful way: make s ...
- Thread线程框架学习
原文:https://www.cnblogs.com/wangkeqin/p/9351299.html Thread线程框架 线程定义:线程可以理解为一个特立独行的函数.其存在的意义,就是并行,避免了 ...
- ThinkPad T410i 2516A21 升級手札(換SSD固態硬碟、I7 CPU、開機20秒)
最近筆記本越來越慢,開機得20分鐘,而且CPU動不動就飆到80度,趁著開學網上活動,準備給老伙計來一次重大升級.查一下主板芯片,最高支持8G內存,已經滿了,光驅位加了一個1T機械硬盤,那麼能升級的就只 ...
- Cocos CreatorUI系统下
若本号内容有做得不到位的地方(比如:涉及版权或其他问题),请及时联系我们进行整改即可,会在第一时间进行处理. 请点赞!因为你们的赞同/鼓励是我写作的最大动力! 欢迎关注达叔小生的简书! 这是一个有质量 ...
- GoCN每日新闻(2019-10-07)
GoCN每日新闻(2019-10-07) 国庆专辑:GopherChina 祝大家国庆节快乐(假期最后一天) GoCN每日新闻(2019-10-07) 1. Go 不好的点:JSON 解析的探 ...
- Python TIPS上一道关于人民币金额小写转大写的题
人民币金额打印 题目链接:here.我发现我写的好复杂,但万幸编码还算符合人类,看了其他答案,感觉都是天书. #!/usr/bin/env python # -*- coding: utf-8 -*- ...
- mysql tan() 函数
mysql> ); +--------------------+ | tan(pi()/) | +--------------------+ | 0.9999999999999999 | +-- ...
- SpringBoot聚合项目打包
1.打包遇到的问题: 子模块打包时,每次打包出来的jar都只有3k左右,没办法运行,目测应该是依赖的jar没有打包进来! 2.解决办法: 2.1.主项目的pom.xml里面不需要打包配置 2.2.在需 ...