当前位置:网站首页>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
)
;
边栏推荐
- Principle and practice of common defects in RSA encryption application
- ETCD数据库源码分析——初始化总览
- flink1.13 sql基础语法(二)join操作
- Encryption and decryption
- Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
- Flask
- Nodejs learning document
- Ping port artifact psping
- Void convolution, deformable convolution, deformable ROI pooling
- Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display
猜你喜欢

Appearance of LabVIEW error dialog box

Simulink and Arduino serial port communication
![[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk](/img/b9/cf4db4f8a5d2ef3fb344258f0e30f5.jpg)
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk

Topological sorting and graphical display of critical path

Etcd database source code analysis - initialization overview
![[paper summary] zero shot semantic segmentation](/img/78/ee64118d86a7e43ec4d1cb97191fbe.jpg)
[paper summary] zero shot semantic segmentation
![[QT] create mycombobox click event](/img/5a/ed17567a71f6737891fc7a8273df0a.png)
[QT] create mycombobox click event

Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
![[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术](/img/87/e0469e280365ed0261e2b551ebd888.png)
[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
随机推荐
cmake
Useful plug-ins for vscode
[matlab] communication signal modulation general function - low pass filter
[matlab] matlab simulates digital bandpass transmission systems - QPSK and OQPSK systems
[MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB
2022 question bank and answers for safety management personnel of hazardous chemical business units
VB.net 调用FFmpeg简单处理视频(类库——6)
中职组网络安全—内存取证
Daily question brushing record (12)
NTFS security permissions
Notepad++--显示相关的配置
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
【QT】定时器
[matlab] matlab simulation modulation system FM system
十二. golang其他
[matlab] matlab simulation modulation system SSB system
Simulink and Arduino serial port communication
Notepad++ -- display related configurations
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
Just do it with your hands 7 - * project construction details 2 - hook configuration