Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

Leetcode Department Top Three Salary problem solution

YASH PAL, 31 July 2024

In this Leetcode Department Top Three Salary problem solution, 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. Write an SQL query to find the employees who are high earners in each of the departments. Return the result table in any order.

Leetcode Department Top Three Salary problem solution

Problem solution in Oracle.

SELECT DEPARTMENT,EMPLOYEE,SALARY
FROM (SELECT D.NAME DEPARTMENT,E.NAME EMPLOYEE,E.SALARY SALARY,
       DENSE_RANK() OVER(PARTITION BY D.ID ORDER BY E.SALARY DESC) RANK
FROM EMPLOYEE E 
     INNER JOIN 
     DEPARTMENT D
ON E.DEPARTMENTID = D.ID)
WHERE RANK <= 3

Problem solution in Mysql.

select department,employee,salary
from
(select d.name as department,e.name as employee,e.salary,
dense_rank() over(partition by departmentid order by salary desc)rm from employee e join department d on e.departmentid=d.id)a
where rm <4

Problem solution in SQL server.

SELECT t.Department, t.Employee, t.Salary FROM ( 
SELECT d.Name As Department, e.Name As Employee, e.Salary, DENSE_RANK() OVER(PARTITION BY e.DepartmentId Order By e.Salary DESC) As row
FROM Employee e INNER Join Department d
    ON e.DepartmentID = d.Id) As t
    Where t.row <=3

coding problems

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes