Skip to content
Programming101
Programmingoneonone

Learn everything about programming

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

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 solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • 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
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes