File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 22
33[ ![ MIT licensed] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( ./LICENSE )
44[ ![ CI] ( https://github.com/ivanbyone/leetcode-sql/actions/workflows/ci.yml/badge.svg )] ( https://github.com/Ivanbyone/leetcode-sql//actions )
5+ ![ Postgres] ( https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white )
56
67## Description
78
@@ -44,6 +45,7 @@ Have a good contributing!
4445 - [ 596. Classes With at Least 5 Students] ( ./leetcode/easy/596.%20Classes%20With%20at%20Least%205%20Students.sql )
45462 . [ Medium] ( ./leetcode/medium/ )
4647 - [ 176. Second Highest Salary] ( ./leetcode/medium/176.%20Second%20Highest%20Salary.sql )
48+ - [ 184. Department Highest Salary] ( ./leetcode/medium/184.%20Department%20Highest%20Salary.sql )
4749
4850## License
4951
Original file line number Diff line number Diff line change 1+ /*
2+ Question 184. Department Highest Salary
3+ Link: https://leetcode.com/problems/department-highest-salary/description/
4+
5+ Table: Employee
6+
7+ +--------------+---------+
8+ | Column Name | Type |
9+ +--------------+---------+
10+ | id | int |
11+ | name | varchar |
12+ | salary | int |
13+ | departmentId | int |
14+ +--------------+---------+
15+ id is the primary key (column with unique values) for this table.
16+ departmentId is a foreign key (reference columns) of the ID from the Department table.
17+ Each row of this table indicates the ID, name, and salary of an employee. It also contains the ID of their department.
18+
19+
20+ Table: Department
21+
22+ +-------------+---------+
23+ | Column Name | Type |
24+ +-------------+---------+
25+ | id | int |
26+ | name | varchar |
27+ +-------------+---------+
28+ id is the primary key (column with unique values) for this table. It is guaranteed that department name is not NULL.
29+ Each row of this table indicates the ID of a department and its name.
30+
31+
32+ Write a solution to find employees who have the highest salary in each of the departments.
33+
34+ Return the result table in any order.
35+ */
36+
37+ SELECT
38+ d .name AS Department,
39+ e .name AS Employee,
40+ e .salary
41+ FROM Employee AS e
42+ LEFT JOIN
43+ Department AS d
44+ ON e .departmentId = d .id
45+ WHERE e .salary = (
46+ SELECT MAX (em .salary )
47+ FROM Employee AS em
48+ WHERE em .departmentId = e .departmentId
49+ )
You can’t perform that action at this time.
0 commit comments