Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Max Salary Per Department

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

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

OpenText wants a compensation report showing the highest-paid employees in each department. Write a PostgreSQL query that returns every employee tied for the maximum non-null salary in their department.

Requirements

  1. Use a window function or equivalent ranking logic to identify the maximum salary per department.
  2. Return all employees sharing that maximum salary, not just one employee.
  3. Include the department name, employee name, and salary.
  4. Exclude employees without a department or salary, and sort by department name followed by employee name.

Schema

departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Name of the department
employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee full name
department_idINTReferences departments.department_id
salaryNUMERIC(12,2)Annual employee salary
Tablesdepartmentsemployees
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results