8000 Add solution of Day-44 · Shubham-Bhoite/LeetCode-MySql@91920b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 91920b2

Browse files
Add solution of Day-44
1 parent 4783a06 commit 91920b2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Solutions/Problem-44.sql

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,19 @@ Each row of this table indicates the ID of a department and its name.
2525
2626
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.
2727
Write a solution to find the employees who are high earners in each of the departments.
28-
*/
28+
*/
29+
30+
31+
WITH RankedSalaries AS (
32+
SELECT
33+
e.id,
34+
e.name AS Employee,
35+
e.salary AS Salary,
36+
d.name AS Department,
37+
DENSE_RANK() OVER (PARTITION BY e.departmentId ORDER BY e.salary DESC) AS rnk
38+
FROM Employee e
39+
JOIN Department d ON e.departmentId = d.id
40+
)
41+
SELECT Department, Employee, Salary
42+
FROM RankedSalaries
43+
WHERE rnk <= 3;

0 commit comments

Comments
 (0)
0