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
Max Salary Per Department
00:00
5 left

Max Salary Per Department

EasySQL · PostgreSQL

Problem

HID WorkforceID needs a salary review showing the highest-paid employee or employees in each department. Write a PostgreSQL query that returns all employees tied for the maximum salary within their department.

Requirements

  1. Join employees to departments and return the department name, employee name, and salary.
  2. Use a window function to rank employees within each department by salary in descending order.
  3. Return every employee tied for the highest non-null salary. Exclude employees whose salary is NULL.
  4. Sort the result by department name and employee name.

Schema

departments
ColumnTypeDescription
department_idPKINTPrimary key for the department
department_nameVARCHAR(100)Department name
locationVARCHAR(100)Primary office location
employees
ColumnTypeDescription
employee_idPKINTPrimary key for the employee
employee_nameVARCHAR(100)Employee's full name
department_idINTReferences departments.department_id
job_titleVARCHAR(100)Employee's job title
salaryNUMERIC(12,2)Annual salary
Tablesdepartmentsemployees
Interviewer

Your question is Max Salary Per Department. 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.