Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Paid Per Department

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Paid Per Department. Start with the requirements and the two tables on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results