Skip to content

Practice Department Top Three Salaries

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#185
LeetCode Problem

Department Top Three Salaries

Problem Statement

Tables: Employee(id INT, name VARCHAR, salary INT, departmentId INT); Department(id INT, name VARCHAR). Employee.id and Department.id are unique keys. Employee.departmentId references Department.id. Return Department, Employee and Salary for employees whose salary is among the top three distinct salaries in their own department. Include all ties, even if this produces more than three employees in a department. Output order is unrestricted.

Source: Department Top Three Salaries on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Employee table: +----+-------+--------+--------------+ | id | name  | salary | departmentId | +----+-------+--------+--------------+ | 1  | Joe   | 85000  | 1            | | 2  | Henry | 80000  | 2            | | 3  | Sam   | 60000  | 2            | | 4  | Max   | 90000  | 1            | | 5  | Janet | 69000  | 1            | | 6  | Randy | 85000  | 1            | | 7  | Will  | 70000  | 1            | +----+-------+--------+--------------+ Department table: +----+-------+ | id | name  | +----+-------+ | 1  | IT    | | 2  | Sales | +----+-------+
Output
+------------+----------+--------+ | Department | Employee | Salary | +------------+----------+--------+ | IT         | Max      | 90000  | | IT         | Joe      | 85000  | | IT         | Randy    | 85000  | | IT         | Will     | 70000  | | Sales      | Henry    | 80000  | | Sales      | Sam      | 60000  | +------------+----------+--------+

Constraints

There are no employees with the exact same name, salary and department.

Related LeetCode Problems

Practice more problems similar to Department Top Three Salaries.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.