Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Department High Earners (Top Three Salaries)
00:00
5 left

Department High Earners (Top Three Salaries)

MediumSQL · PostgreSQL

Problem

TCS iON workforce reporting needs a query that identifies high-earning employees within every department. An employee is a high earner when their salary belongs to one of the department's top three unique, non-NULL salary values.

Write a PostgreSQL query that returns all qualifying employees, including every employee tied at one of those salary levels.

Requirements

  1. Join employees to their department names.
  2. Rank distinct salary levels independently within each department, with the highest salary ranked first.
  3. Return all employees whose salary rank is 1, 2, or 3. Do not return employees with NULL salaries or employees without a valid department.
  4. Include departments with fewer than three salary levels by returning every available qualifying level.
  5. Order the output by department name, salary rank, salary descending, and employee ID.

Schema

departments
ColumnTypeDescription
department_idPKINTEGERUnique department identifier
department_nameVARCHAR(100)Name of the department
employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
department_idINTEGEREmployee's department identifier
salaryNUMERIC(12,2)Annual employee salary
Tablesdepartmentsemployees
Interviewer

Your question is Department High Earners (Top Three Salaries). 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.