当前位置:网站首页>力扣(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
)
;
边栏推荐
- Web Components
- Bidirectional RNN and stacked bidirectional RNN
- 数组、、、
- Common functions of go-2-vim IDE
- 【全网首发】(大表小技巧)有时候 2 小时的 SQL 操作,可能只要 1 分钟
- 【tcp】服务器上tcp连接状态json形式输出
- How can gbase 8C database view the login information of the login user, such as the date, time and IP of the last login authentication?
- Advanced scaffold development
- iframe
- Node の MongoDB Driver
猜你喜欢
In the year of "mutual entanglement" of mobile phone manufacturers, the "machine sea tactics" failed, and the "slow pace" playing method rose
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
32:第三章:开发通行证服务:15:浏览器存储介质,简介;(cookie,Session Storage,Local Storage)
csdn软件测试入门的测试基本流程
基于昇腾AI丨爱笔智能推出银行网点数字化解决方案,实现从总部到网点的信息数字化全覆盖
Basic testing process of CSDN Software Testing Introduction
DGL中的消息传递相关内容的讲解
修复动漫1K变8K
32: Chapter 3: development of pass service: 15: Browser storage media, introduction; (cookie,Session Storage,Local Storage)
9、 Disk management
随机推荐
华为设备配置信道切换业务不中断
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
2022年危险化学品经营单位主要负责人特种作业证考试题库及答案
SQL Server monitoring statistics blocking script information
LSTM applied to MNIST dataset classification (compared with CNN)
Go-2-Vim IDE常用功能
中职组网络安全C模块全漏洞脚本讲解包含4个漏洞的脚本
9、 Disk management
How can gbase 8C database view the login information of the login user, such as the date, time and IP of the last login authentication?
字符串、、
go语言学习笔记-初识Go语言
赛克瑞浦动力电池首台产品正式下线
Operators
dsPIC33EP 时钟初始化程序
数据类型、
Solution to the length of flex4 and Flex3 combox drop-down box
uniapp
Basic testing process of CSDN Software Testing Introduction
沟通的艺术III:看人之间 之倾听
Implement the rising edge in C #, and simulate the PLC environment to verify the difference between if statement using the rising edge and not using the rising edge