当前位置:网站首页>力扣(LeetCode)185. 部门工资前三高的所有员工(2022.07.04)
力扣(LeetCode)185. 部门工资前三高的所有员工(2022.07.04)
2022-07-05 10:42:00 【ChaoYue_miku】
表: Employee
±-------------±--------+
| Column Name | Type |
±-------------±--------+
| id | int |
| name | varchar |
| salary | int |
| departmentId | int |
±-------------±--------+
Id是该表的主键列。
departmentId是Department表中ID的外键。
该表的每一行都表示员工的ID、姓名和工资。它还包含了他们部门的ID。
表: Department
±------------±--------+
| Column Name | Type |
±------------±--------+
| id | int |
| name | varchar |
±------------±--------+
Id是该表的主键列。
该表的每一行表示部门ID和部门名。
公司的主管们感兴趣的是公司每个部门中谁赚的钱最多。一个部门的 高收入者 是指一个员工的工资在该部门的 不同 工资中 排名前三 。
编写一个SQL查询,找出每个部门中 收入高的员工 。
以 任意顺序 返回结果表。
查询结果格式如下所示。
示例 1:
输入:
Employee 表:
±—±------±-------±-------------+
| id | name | salary | departmentId |
±—±------±-------±-------------+
| 1 | Joe | 85000 | 1 |
| 2 | Henry | 80000 | 2 |
| 3 | Sam | 60000 | 2 |
| 4 | Max | 90000 | 1 |
| 5 | Janet | 69000 | 1 |
| 6 | Randy | 85000 | 1 |
| 7 | Will | 70000 | 1 |
±—±------±-------±-------------+
Department 表:
±—±------+
| id | name |
±—±------+
| 1 | IT |
| 2 | Sales |
±—±------+
输出:
±-----------±---------±-------+
| Department | Employee | Salary |
±-----------±---------±-------+
| IT | Max | 90000 |
| IT | Joe | 85000 |
| IT | Randy | 85000 |
| IT | Will | 70000 |
| Sales | Henry | 80000 |
| Sales | Sam | 60000 |
±-----------±---------±-------+
解释:
在IT部门:
- Max的工资最高
- 兰迪和乔都赚取第二高的独特的薪水
- 威尔的薪水是第三高的
在销售部:
- 亨利的工资最高
- 山姆的薪水第二高
- 没有第三高的工资,因为只有两名员工
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/department-top-three-salaries
MySQL提交内容:
# Write your MySQL query statement below
SELECT
d.Name AS 'Department', e1.Name AS 'Employee', e1.Salary
FROM
Employee e1
JOIN
Department d ON e1.DepartmentId = d.Id
WHERE
3 > (SELECT
COUNT(DISTINCT e2.Salary)
FROM
Employee e2
WHERE
e2.Salary > e1.Salary
AND e1.DepartmentId = e2.DepartmentId
)
;
边栏推荐
- 【js学习笔记五十四】BFC方式
- vite//
- iframe
- Solution to the length of flex4 and Flex3 combox drop-down box
- Based on shengteng AI Aibi intelligence, we launched a digital solution for bank outlets to achieve full digital coverage of information from headquarters to outlets
- Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report
- [可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename……
- Explanation of full vulnerability script of network security C module of secondary vocational group script containing 4 vulnerabilities
- LSTM applied to MNIST dataset classification (compared with CNN)
- Scaffold development foundation
猜你喜欢

About the use of Vray 5.2 (self research notes)

【JS】提取字符串中的分数,汇总后算出平均分,并与每个分数比较,输出

基于昇腾AI丨以萨技术推出视频图像全目标结构化解决方案,达到业界领先水平

在C# 中实现上升沿,并模仿PLC环境验证 If 语句使用上升沿和不使用上升沿的不同

Go语言-1-开发环境配置

【广告系统】Parameter Server分布式训练

The first product of Sepp power battery was officially launched

9、 Disk management

LSTM applied to MNIST dataset classification (compared with CNN)

关于vray 5.2的使用(自研笔记)(二)
随机推荐
小程序框架Taro
iframe
beego跨域问题解决方案-亲试成功
When using gbase 8C database, an error is reported: 80000502, cluster:%s is busy. What's going on?
How to close the log window in vray5.2
[vite] 1371 - develop vite plug-ins by hand
flex4 和 flex3 combox 下拉框长度的解决办法
csdn软件测试入门的测试基本流程
小红书自研KV存储架构如何实现万亿量级存储与跨云多活
Coneroller执行时候的-26374及-26377错误
Sqlserver regularly backup database and regularly kill database deadlock solution
iframe
LSTM applied to MNIST dataset classification (compared with CNN)
在C# 中实现上升沿,并模仿PLC环境验证 If 语句使用上升沿和不使用上升沿的不同
Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report
Based on shengteng AI Yisa technology, it launched a full target structured solution for video images, reaching the industry-leading level
What are the top ten securities companies? Is it safe to open an account online?
使用GBase 8c数据库过程中报错:80000502,Cluster:%s is busy,是怎么回事?
运算符、、
A mining of edu certificate station