Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Salaries by Department in Oracle
00:00
5 left

Top Salaries by Department in Oracle

EasySQL · PostgreSQL

Problem

The Plymouth Rock People Operations team needs a department-level view of its highest-paid employees. Write a PostgreSQL query that returns the top five salaries within each department.

Requirements

  1. Join employees to departments using department_id.
  2. Rank employees separately within each department by salary from highest to lowest.
  3. Return no more than five employees per department, using employee_id as the deterministic tie-breaker.
  4. Sort the final results by department name and salary rank. Employees with NULL salaries should not appear in the top five when a department has at least five non-NULL salaries.

Schema

departments
ColumnTypeDescription
department_idPKINTEGERPrimary key for the department
department_nameVARCHAR(100)Name of the Plymouth Rock department
employees
ColumnTypeDescription
employee_idPKINTEGERPrimary key for the employee
employee_nameVARCHAR(100)Employee's full name
department_idINTEGERReferences departments.department_id
salaryNUMERIC(10,2)Annual salary in dollars
Tablesemployeesdepartments
Interviewer

Your question is Top Salaries by Department in Oracle. 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.