Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Top Salary Query

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

Your question is SQL Top Salary Query. 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

Ness Digital Engineering needs a salary review query for its employee reporting system. Write a PostgreSQL query that identifies every employee whose salary is the third-highest distinct salary in the salary table.

Requirements

  1. Rank distinct salary amounts from highest to lowest using a window function.
  2. Return all employees tied at the third-highest salary, not just one employee.
  3. Join the ranked salary records to employees and return employee details with the salary.
  4. Sort the final results by employee_id.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
full_nameVARCHAR(100)Employee full name
departmentVARCHAR(80)Ness department
job_titleVARCHAR(100)Employee job title
salary
ColumnTypeDescription
salary_idPKINTUnique salary record identifier
employee_idINTEmployee identifier associated with the salary record
salary_amountNUMERIC(12,2)Employee salary amount
Tablesemployeessalary
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results