Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Department-Wise Second Highest Salary

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

Your question is Department-Wise Second Highest Salary. 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

Incedo's workforce analytics team needs to identify the second-highest salary in each department. Write a PostgreSQL query using department and employee data.

Requirements

  1. Return every employee whose salary is the second-highest distinct salary in their department.
  2. Treat tied salaries as the same salary rank and return all employees sharing rank 2.
  3. Exclude employees whose salary is NULL and departments with fewer than two distinct non-null salaries.
  4. Return results ordered by department name and employee name.

Schema

departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department name
employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee name
department_idINTReferences 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