Skip to content

Commit 14ca9e8

Browse files
committed
Upload 146
1 parent 9f16f44 commit 14ca9e8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ The problems and both submitted and site solutions are documented in individual
178178
| 143 | [Rank Scores](https://leetcode.com/problems/rank-scores/description/) | [Solution](solutions/143_rank_scores.md) | LeetCode | Medium | |
179179
| 144 | [Customers Who Never Order](https://leetcode.com/problems/customers-who-never-order/description/) | [Solution](solutions/144_customers_who_never_order.md) | LeetCode | Easy | |
180180
| 145 | [Game Play Analysis I](https://leetcode.com/problems/game-play-analysis-i/description/) | [Solution](solutions/145_game_play_analysis_i.md) | LeetCode | Easy | |
181+
| 146 | [Department Highest Salary](https://leetcode.com/problems/department-highest-salary/description/) | [Solution](solutions/146_department_highest_salary.md) | LeetCode | Medium | |
181182
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
182183

183184
## Author(s)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SQL Everyday \#146
2+
3+
## Department Highest Salary
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
Write a solution to find employees who have the highest salary in each of the departments.
11+
12+
Return the result table in *any order*. [[Full Description](https://leetcode.com/problems/department-highest-salary/description/)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
WITH cte AS (
19+
SELECT
20+
d.name AS Department
21+
,e.name AS Employee
22+
,salary AS Salary
23+
,RANK() OVER (PARTITION BY e.departmentID ORDER BY e.salary DESC) AS rownum
24+
FROM Employee AS e
25+
JOIN Department AS d ON e.departmentID = d.id
26+
)
27+
SELECT
28+
Department
29+
,Employee
30+
,Salary
31+
FROM cte
32+
WHERE rownum = 1
33+
ORDER BY Salary DESC
34+
;
35+
```
36+
37+
## Site Solution
38+
39+
```sql
40+
-- LeetCode Solution
41+
-- TBD
42+
```
43+
44+
## Notes
45+
46+
TBD
47+
48+
## NB
49+
50+
TBD
51+
52+
Go to [Index](../?tab=readme-ov-file#index)\
53+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)