当前位置:网站首页>Leetcode 185 All employees with the top three highest wages in the Department (July 4, 2022)
Leetcode 185 All employees with the top three highest wages in the Department (July 4, 2022)
2022-07-05 11:05:00 【ChaoYue_ miku】
surface : Employee
±-------------±--------+
| Column Name | Type |
±-------------±--------+
| id | int |
| name | varchar |
| salary | int |
| departmentId | int |
±-------------±--------+
Id Is the primary key column of the table .
departmentId yes Department In the table ID The foreign key .
Each row of the table represents the employee's ID、 Name and salary . It also includes their department's ID.
surface : Department
±------------±--------+
| Column Name | Type |
±------------±--------+
| id | int |
| name | varchar |
±------------±--------+
Id Is the primary key column of the table .
Each row of the table represents the Department ID And department name .
Company executives are interested in who makes the most money in each department of the company . Of a department High income earners It refers to the salary of an employee in the... Of the Department Different In salary Top three .
Write a SQL Inquire about , Find out... In each department High paid employees .
With In any order Return result table .
The query result format is as follows .
Example 1:
Input :
Employee surface :
±—±------±-------±-------------+
| 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 surface :
±—±------+
| id | name |
±—±------+
| 1 | IT |
| 2 | Sales |
±—±------+
Output :
±-----------±---------±-------+
| Department | Employee | Salary |
±-----------±---------±-------+
| IT | Max | 90000 |
| IT | Joe | 85000 |
| IT | Randy | 85000 |
| IT | Will | 70000 |
| Sales | Henry | 80000 |
| Sales | Sam | 60000 |
±-----------±---------±-------+
explain :
stay IT department :
- Max The highest salary
- Randy and Joe both earn the second highest unique salary
- Will's salary is the third highest
In the Sales Department :
- Henry's salary is the highest
- Sam's salary is the second highest
- There is no third highest salary , Because there are only two employees
source : Power button (LeetCode)
link :https://leetcode.cn/problems/department-top-three-salaries
MySQL Submission :
# 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
)
;
边栏推荐
猜你喜欢

Go language learning notes - first acquaintance with go language

Talk about the understanding of fault tolerance mechanism and state consistency in Flink framework

如何将 DevSecOps 引入企业?

How to close the log window in vray5.2

基于昇腾AI丨以萨技术推出视频图像全目标结构化解决方案,达到业界领先水平

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

2022 mobile crane driver examination question bank and simulation examination

小红书自研KV存储架构如何实现万亿量级存储与跨云多活

DDR4的特性与电气参数

Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report
随机推荐
Talk about the understanding of fault tolerance mechanism and state consistency in Flink framework
A mining of edu certificate station
2022鹏城杯web
华为设备配置信道切换业务不中断
Codeforces Round #804 (Div. 2)
Go language-1-development environment configuration
Nine degrees 1480: maximum ascending subsequence sum (dynamic programming idea for the maximum value)
[JS learning notes 54] BFC mode
关于vray 5.2的使用(自研笔记)(二)
Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
磨礪·聚變|知道創宇移動端官網煥新上線,開啟數字安全之旅!
正则表达式
Some understandings of heterogeneous graphs in DGL and the usage of heterogeneous graph convolution heterographconv
力扣(LeetCode)185. 部门工资前三高的所有员工(2022.07.04)
Common functions of go-2-vim IDE
流程控制、
Explanation of full vulnerability script of network security C module of secondary vocational group script containing 4 vulnerabilities
使用GBase 8c数据库过程中报错:80000502,Cluster:%s is busy,是怎么回事?
deepfake教程
Basic testing process of CSDN Software Testing Introduction