当前位置:网站首页>Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
2022-07-04 05:24: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')
surface : Employee
±-------------±--------+
| Name | type |
±-------------±--------+
| id | int |
| name | varchar |
| salary | int |
| departmentId | int |
±-------------±--------+
id Is the primary key column of this table .
departmentId yes Department In the table ID The foreign key .
Each row of this table represents the employee's ID、 Name and salary . It also includes their department's ID.
surface : Department
±------------±--------+
| Name | type |
±------------±--------+
| id | int |
| name | varchar |
±------------±--------+
id Is the primary key column of this table .
Each row of this table represents the of a department ID And its name .
To write SQL Query to find the highest paid employee in each department .
Press In any order Return result table .
The query result format is shown in the following example .
Example 1:
Input :
Employee surface :
±—±------±-------±-------------+
| 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 surface :
±—±------+
| id | name |
±—±------+
| 1 | IT |
| 2 | Sales |
±—±------+
Output :
±-----------±---------±-------+
| Department | Employee | Salary |
±-----------±---------±-------+
| IT | Jim | 90000 |
| Sales | Henry | 80000 |
| IT | Max | 90000 |
±-----------±---------±-------+
explain :Max and Jim stay IT The wages of all departments are the highest ,Henry The highest salary is in the sales department .
source : Power button (LeetCode)
link :https://leetcode.cn/problems/department-highest-salary
Method 1 :JOIN and IN sentence
MySQL Submission :
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
)
;
边栏推荐
- Daily question brushing record (12)
- [matlab] matlab simulation - simulate the AM modulation process of the modulation system
- [high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk
- [matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
- 2022g2 power station boiler stoker special operation certificate examination question bank and answers
- KMP匹配字符串
- [matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)
- VB.net 调用FFmpeg简单处理视频(类库——6)
- Unity2d -- character moves and turns
- 基于单片机的太阳能杀虫系统
猜你喜欢

C basic (VII) document operation

2022 a special equipment related management (elevator) examination questions simulation examination platform operation

A summary of the 8544 problem that SolidWorks Standard cannot obtain a license

如何使用postman实现简单的接口关联【增删改查】

Evolution of system architecture: differences and connections between SOA and microservice architecture

How to build your own knowledge engine? Community open application

Signification des lettres du module optique et abréviation des paramètres Daquan

Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard

中科磐云—2022广东木马信息获取解析

Zhongke panyun-d module analysis and scoring standard
随机推荐
2022 Guangdong provincial competition - code information acquisition and analysis flag
Enterprise level log analysis system elk (if things backfire, there must be other arrangements)
Remote desktop client RDP
Unity2D--人物移动并转身
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
[MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB
Ping port artifact psping
Signification des lettres du module optique et abréviation des paramètres Daquan
LabVIEW错误对话框的出现
Simulink and Arduino serial port communication
全国职业院校技能大赛(中职组)网络安全竞赛试题—解析
Notes on the paper "cross view transformers for real time map view semantic segmentation"
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)
[matlab] matlab simulates digital bandpass transmission systems - QPSK and OQPSK systems
VB.net 调用FFmpeg简单处理视频(类库——6)
中职组网络安全—内存取证
Li Kou's 300th weekly match
EVM proof in appliedzkp zkevm (11)
Zzulioj:1201: mode problem