You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,6 +168,7 @@ The problems and both submitted and site solutions are documented in individual
168
168
| 133 |[Restaurant Growth](https://leetcode.com/problems/restaurant-growth/description/)|[Solution](solutions/133_restaurant_growth.md)| LeetCode | Medium ||
169
169
| 134 |[Friend Requests II: Who Has the Most Friends](https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends/description/)|[Solution](solutions/134_friend_requests_ii_who_has_the_most_friends.md)| LeetCode | Medium |`UNION ALL`|
170
170
| 135 |[Investments in 2016](https://leetcode.com/problems/investments-in-2016/description/)|[Solution](solutions/135_investments_in_2016.md)| LeetCode | Medium ||
171
+
| 136 |[Department Top Three Salaries](https://leetcode.com/problems/department-top-three-salaries/description/)|[Solution](solutions/136_department_top_three_salaries.md)| LeetCode | Hard ||
171
172
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
A company's executives are interested in seeing who earns the most money in each of the company's departments. A *high earner* in a department is an employee who has a salary in the *top three unique* salaries for that department.
11
+
12
+
Write a solution to find the employees who are *high earners* in each of the departments.
13
+
14
+
Return the result table *in any order*. [[Full Description](https://leetcode.com/problems/department-top-three-salaries/description/)]
15
+
16
+
## Submitted Solution
17
+
18
+
```sql
19
+
-- Submitted Solution
20
+
WITH cte AS (
21
+
SELECT
22
+
d.nameAS Department
23
+
,e.nameAS Employee
24
+
,e.salaryAS Salary
25
+
,DENSE_RANK() OVER (PARTITION BY d.nameORDER BYe.salaryDESC) AS rank
26
+
FROM Employee AS e
27
+
JOIN Department AS d ONe.departmentId=d.id
28
+
)
29
+
SELECT
30
+
Department
31
+
,Employee
32
+
,Salary
33
+
FROM cte
34
+
WHERE rank <=3
35
+
ORDER BY Department ASC, Employee ASC, Salary DESC
0 commit comments