当前位置:网站首页>力扣(LeetCode)184. 部门工资最高的员工(2022.07.03)
力扣(LeetCode)184. 部门工资最高的员工(2022.07.03)
2022-07-04 04:59:00 【ChaoYue_miku】
Create table If Not Exists Employee (id int, name varchar(255), salary int, departmentId int)
Create table If Not Exists Department (id int, name varchar(255))
Truncate table Employee
insert into Employee (id, name, salary, departmentId) values ('1', 'Joe', '70000', '1')
insert into Employee (id, name, salary, departmentId) values ('2', 'Jim', '90000', '1')
insert into Employee (id, name, salary, departmentId) values ('3', 'Henry', '80000', '2')
insert into Employee (id, name, salary, departmentId) values ('4', 'Sam', '60000', '2')
insert into Employee (id, name, salary, departmentId) values ('5', 'Max', '90000', '1')
Truncate table Department
insert into Department (id, name) values ('1', 'IT')
insert into Department (id, name) values ('2', 'Sales')
表: Employee
±-------------±--------+
| 列名 | 类型 |
±-------------±--------+
| id | int |
| name | varchar |
| salary | int |
| departmentId | int |
±-------------±--------+
id是此表的主键列。
departmentId是Department表中ID的外键。
此表的每一行都表示员工的ID、姓名和工资。它还包含他们所在部门的ID。
表: Department
±------------±--------+
| 列名 | 类型 |
±------------±--------+
| id | int |
| name | varchar |
±------------±--------+
id是此表的主键列。
此表的每一行都表示一个部门的ID及其名称。
编写SQL查询以查找每个部门中薪资最高的员工。
按 任意顺序 返回结果表。
查询结果格式如下例所示。
示例 1:
输入:
Employee 表:
±—±------±-------±-------------+
| id | name | salary | departmentId |
±—±------±-------±-------------+
| 1 | Joe | 70000 | 1 |
| 2 | Jim | 90000 | 1 |
| 3 | Henry | 80000 | 2 |
| 4 | Sam | 60000 | 2 |
| 5 | Max | 90000 | 1 |
±—±------±-------±-------------+
Department 表:
±—±------+
| id | name |
±—±------+
| 1 | IT |
| 2 | Sales |
±—±------+
输出:
±-----------±---------±-------+
| Department | Employee | Salary |
±-----------±---------±-------+
| IT | Jim | 90000 |
| Sales | Henry | 80000 |
| IT | Max | 90000 |
±-----------±---------±-------+
解释:Max 和 Jim 在 IT 部门的工资都是最高的,Henry 在销售部的工资最高。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/department-highest-salary
方法一:JOIN和IN语句
MySQL提交内容:
SELECT
Department.name AS 'Department',
Employee.name AS 'Employee',
Salary
FROM
Employee
JOIN
Department ON Employee.DepartmentId = Department.Id
WHERE
(Employee.DepartmentId , Salary) IN
( SELECT
DepartmentId, MAX(Salary)
FROM
Employee
GROUP BY DepartmentId
)
;
边栏推荐
- 【MATLAB】MATLAB 仿真数字基带传输系统 — 双极性基带信号(余弦滚降成形脉冲)的眼图
- Programming example of stm32f1 and stm32subeide -74hc595 drives 4-bit 7-segment nixie tube
- Evolution of system architecture: differences and connections between SOA and microservice architecture
- We believe that the development of consumer Internet will still be limited to the Internet industry itself
- LM small programmable controller software (based on CoDeSys) note XXI: error 3703
- 【MATLAB】MATLAB 仿真 — 窄带高斯白噪声
- 补某视频网站的js,进行视频解密
- LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
- [matlab] matlab simulation modulation system - VSB system
- 【MATLAB】MATLAB 仿真模拟调制系统 — SSB 系统
猜你喜欢
随机推荐
Flink1.13 SQL basic syntax (I) DDL, DML
The first introduction, stages and methods of defense system breakthrough from the perspective of the red team
Unity2d -- character moves and turns
Automated testing selenium foundation -- webdriverapi
2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
[paper summary] zero shot semantic segmentation
Several smart watch related chips Bluetooth chip low power consumption
2022年R2移动式压力容器充装复训题库及答案
加密和解密
2022G2电站锅炉司炉特种作业证考试题库及答案
The second case analysis of the breakthrough of defense system from the perspective of the red team
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
TCP状态转换图
EVM proof in appliedzkp zkevm (11)
简易零钱通
【MATLAB】MATLAB 仿真模拟调制系统 — SSB 系统
企业级日志分析系统ELK(如果事与愿违那一定另有安排)
【MATLAB】MATLAB 仿真 — 低通高斯白噪声
空洞卷积、可变形卷积、可变形ROI Pooling
Notepad++ -- display related configurations








