当前位置:网站首页>力扣(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
)
;
边栏推荐
猜你喜欢
关于vray5.2怎么关闭日志窗口
Bidirectional RNN and stacked bidirectional RNN
2022年流动式起重机司机考试题库及模拟考试
Go语言-1-开发环境配置
32:第三章:开发通行证服务:15:浏览器存储介质,简介;(cookie,Session Storage,Local Storage)
关于vray 5.2的使用(自研笔记)(二)
32: Chapter 3: development of pass service: 15: Browser storage media, introduction; (cookie,Session Storage,Local Storage)
DGL中异构图的一些理解以及异构图卷积HeteroGraphConv的用法
小红书自研KV存储架构如何实现万亿量级存储与跨云多活
Some understandings of heterogeneous graphs in DGL and the usage of heterogeneous graph convolution heterographconv
随机推荐
SQL Server monitoring statistics blocking script information
Taro进阶
Cross page communication
C语言活期储蓄账户管理系统
修复动漫1K变8K
中职组网络安全C模块全漏洞脚本讲解包含4个漏洞的脚本
2022年流动式起重机司机考试题库及模拟考试
[可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename……
Some understandings of heterogeneous graphs in DGL and the usage of heterogeneous graph convolution heterographconv
uniapp
【js学习笔记五十四】BFC方式
关于 “原型” 的那些事你真的理解了吗?【上篇】
华为设备配置信道切换业务不中断
九、磁盘管理
2022年危险化学品生产单位安全生产管理人员特种作业证考试题库模拟考试平台操作
Honing · fusion | know that the official website of Chuangyu mobile terminal is newly launched, and start the journey of digital security!
Data types ntext and varchar are incompatible in the not equal to operator - 95 small pang
Go语言-1-开发环境配置
LDAP overview
Review the whole process of the 5th Polkadot Hackathon entrepreneurship competition, and uncover the secrets of the winning projects!