当前位置:网站首页>力扣(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
)
;
边栏推荐
- Notes on the paper "cross view transformers for real time map view semantic segmentation"
- [matlab] communication signal modulation general function interpolation function
- Annex 4: scoring criteria of the attacker docx
- PostgreSQL has officially surpassed mysql. Is this guy too strong!
- appliedzkp的zkevm(12)State Proof
- 【MATLAB】MATLAB 仿真数字带通传输系统 — ASK、 PSK、 FSK 系统
- Sécurité du réseau dans les écoles professionnelles secondaires - preuve de mémoire
- Just do it with your hands 7 - * project construction details 2 - hook configuration
- Flask
- ETCD数据库源码分析——初始化总览
猜你喜欢

c语言经典指针和数组笔试题解析

Detailed comparison of Hynix emmc5.0 and 5.1 series

如何使用postman实现简单的接口关联【增删改查】
![[paper summary] zero shot semantic segmentation](/img/78/ee64118d86a7e43ec4d1cb97191fbe.jpg)
[paper summary] zero shot semantic segmentation

Flutter calls Gaode map app to realize location search, route planning and reverse geocoding

企业级日志分析系统ELK(如果事与愿违那一定另有安排)

中職組網絡安全—內存取證

Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)

2022G2电站锅炉司炉特种作业证考试题库及答案

A summary of the 8544 problem that SolidWorks Standard cannot obtain a license
随机推荐
appliedzkp的zkevm(12)State Proof
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
[matlab] general function of communication signal modulation - generation of narrow-band Gaussian white noise
2022G2电站锅炉司炉特种作业证考试题库及答案
Annex 2-2 confidentiality commitment docx
Analysis of classical pointer and array written test questions in C language
Zhongke Panyun - data analysis and forensics packet flag
中科磐云—2022广东木马信息获取解析
Unity2D--人物移动并转身
Integer type of C language
Just do it with your hands 7 - * project construction details 2 - hook configuration
[matlab] general function of communication signal modulation Fourier transform
Daily question brushing record (12)
Zhongke panyun-d module analysis and scoring standard
光模块字母含义及参数简称大全
ping端口神器psping
Notepad++ -- display related configurations
TCP状态转换图
模拟小根堆
2022年R2移动式压力容器充装复训题库及答案