Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Max Salary Per Department
00:00
5 left

Max Salary Per Department

EasySQL · PostgreSQL

Problem

HID WorkforceID needs a salary review showing the highest-paid employee or employees in each department. Write a PostgreSQL query that returns all employees tied for the maximum salary within their department.

Requirements

  1. Join employees to departments and return the department name, employee name, and salary.
  2. Use a window function to rank employees within each department by salary in descending order.
  3. Return every employee tied for the highest non-null salary. Exclude employees whose salary is NULL.
  4. Sort the result by department name and employee name.

Schema

departments
ColumnTypeDescription
department_idPKINTPrimary key for the department
department_nameVARCHAR(100)Department name
locationVARCHAR(100)Primary office location
employees
ColumnTypeDescription
employee_idPKINTPrimary key for the employee
employee_nameVARCHAR(100)Employee's full name
department_idINTReferences departments.department_id
job_titleVARCHAR(100)Employee's job title
salaryNUMERIC(12,2)Annual salary
Tablesdepartmentsemployees
Interviewer

Your question is Max Salary 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.