Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Paid Per Department
00:00
5 left

Top Paid Per Department

EasySQL · PostgreSQL

Problem

DaDa's HR analytics team wants a department-level compensation report. Write a SQL query to find the top 3 highest-paid employees in each department.

Requirements

  1. Return each employee's department, employee name, and salary.
  2. Rank employees within each department by salary from highest to lowest.
  3. Include only the top 3 employees per department.
  4. Break salary ties by employee_id in ascending order so the result is deterministic.

Schema

departments
ColumnTypeDescription
department_idPKINTPrimary key for the department
department_nameVARCHAR(100)Department name
employees
ColumnTypeDescription
employee_idPKINTPrimary key for the employee
employee_nameVARCHAR(100)Employee full name
department_idINTForeign key to departments.department_id
salaryNUMERIC(12,2)Annual salary
Tablesdepartmentsemployees
Interviewer

Your question is Top Paid Per Department. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.