Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Highest Salary by Department

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

Your question is Highest Salary by 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

Caterpillar's workforce analytics team needs a department-level view of compensation. Write a PostgreSQL query that identifies the employee or employees with the highest non-null annual salary in every department represented in the employee data.

Requirements

  1. Join employees to departments using department_id.
  2. Return the department name, employee name, and highest annual salary.
  3. Include every employee tied for the highest salary in a department.
  4. Exclude employees whose salary is NULL, and sort the result by department name and employee name.

Schema

departments
ColumnTypeDescription
department_idPKINTEGERUnique department identifier
department_nameVARCHAR(100)Caterpillar department name
employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee full name
department_idINTEGERDepartment assigned to the employee
annual_salaryNUMERIC(12,2)Annual salary in U.S. dollars
Tablesdepartmentsemployees
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results