Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Leetcode Department Top Three Salary problem solution

YASH PAL, 31 July 202419 January 2026

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

Leetcode Department Top Three Salary 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

Department Top Three Salary 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 solutions Leetcode Problems Solutions Leetcode

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes