当前位置:网站首页>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
)
;
边栏推荐
- 使用bat命令一键启动常用浏览器
- 使用GBase 8c数据库过程中报错:80000502,Cluster:%s is busy,是怎么回事?
- 磨礪·聚變|知道創宇移動端官網煥新上線,開啟數字安全之旅!
- Go-3-the first go program
- 四部门:从即日起至10月底开展燃气安全“百日行动”
- 第五届 Polkadot Hackathon 创业大赛全程回顾,获胜项目揭秘!
- websocket
- Talk about the understanding of fault tolerance mechanism and state consistency in Flink framework
- Basic testing process of CSDN Software Testing Introduction
- deepfake教程
猜你喜欢

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

磨礪·聚變|知道創宇移動端官網煥新上線,開啟數字安全之旅!

go语言学习笔记-初识Go语言

matlab cov函数详解

Explanation of message passing in DGL
![[advertising system] incremental training & feature access / feature elimination](/img/14/ac596fa4d92e7b245e08cea014a4ab.png)
[advertising system] incremental training & feature access / feature elimination

2022年流动式起重机司机考试题库及模拟考试

Go language learning notes - first acquaintance with go language

Repair animation 1K to 8K

Codeforces Round #804 (Div. 2)
随机推荐
关于vray 5.2的使用(自研笔记)(二)
LDAP overview
A mining of edu certificate station
Wechat nucleic acid detection appointment applet system graduation design completion (8) graduation design thesis template
一次edu证书站的挖掘
Data type
购买小间距LED显示屏的三个建议
Sqlserver regularly backup database and regularly kill database deadlock solution
Basic part - basic project analysis
When using gbase 8C database, an error is reported: 80000502, cluster:%s is busy. What's going on?
Lombok 同时使⽤@Data和@Builder 的坑,你中招没?
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
Web3基金会「Grant计划」赋能开发者,盘点四大成功项目
关于vray 5.2的使用(自研笔记)
Repair animation 1K to 8K
regular expression
Characteristics and electrical parameters of DDR4
Share Net lightweight ORM
四部门:从即日起至10月底开展燃气安全“百日行动”
Variables///