Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Third Largest Salary Query

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

Your question is Third Largest Salary Query. Start with the requirements and the one table 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

Teradata Vantage HR analysts need to identify employees whose compensation is at the third-highest distinct salary level. Write a PostgreSQL query against the employees table.

Requirements

  1. Rank distinct non-null salary values from highest to lowest using a window function.
  2. Return every employee earning the third-highest salary, including ties.
  3. Return employee_id, employee_name, department, and salary, ordered by employee_id.

Use DENSE_RANK() rather than ROW_NUMBER() because multiple employees can share the same salary, and tied salary values should receive the same rank.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
departmentVARCHAR(80)Organizational department
salaryNUMERIC(12,2)Annual salary
Tablesemployees
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results