Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Top Salary Query
00:00
5 left

SQL Top Salary Query

MediumSQL · PostgreSQL

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.
  5. Ignore salary records whose salary_amount is NULL; they must not take part in the ranking.

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
Interviewer

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