Top Three Salaries
Microsoft ☯️ Medium SQL
Beginner Mode

Objective

Write a SQL query to find the top 3 highest-paid employees within each department.

Table Schema:

  • employee
Column Type Description
employee_id INTEGER Unique identifier for each employee
employee_name VARCHAR Name of the employee
salary DECIMAL Employee's salary
department_id INTEGER ID of the department where the employee works
hire_date DATE Date when the employee was hired
  • department
Column Type Description
department_id INTEGER Unique identifier for each department
department_name VARCHAR Name of the department

Task Requirements:

  • Join employee and department tables
  • Identify the top 3 highest-paid employees in each department
  • Order by department name (ascending), then salary (descending), then employee name (ascending)

Output columns: employee_name, department_name, salary

Examples

Example 1:

Input:

department
department_iddepartment_name
1Engineering
2Marketing
employee
department_idemployee_idemployee_namehire_datesalary
11Alice Johnson2020-01-1595000
12Bob Smith2021-03-2085000
13Carol Davis2019-06-1090000
24David Wilson2022-02-0578000
25Emma Brown2021-08-1282000

Output:
department_nameemployee_namesalary
EngineeringAlice Johnson95000
EngineeringCarol Davis90000
EngineeringBob Smith85000
MarketingEmma Brown82000
MarketingDavid Wilson78000
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →