Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top N by Group Salary

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

Your question is Top N by Group Salary. 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

Meta People Analytics wants the top paid people in a specific org unit, such as fb groups or ig reels. Write a PostgreSQL query to return the top N people by salary within one group or department.

Requirements

  1. Join the employee and group tables on the group key.
  2. Filter to one target group or department.
  3. Rank people by salary from highest to lowest, breaking ties by employee_id ascending.
  4. Return only the top N rows for that group.

Schema

employees
ColumnTypeDescription
employee_idPKINTPrimary key for the employee
full_nameVARCHAR(255)Employee name
group_idINTReferences org_groups.group_id
salary_usdNUMERIC(12,2)Annual salary in USD
hire_dateDATEHire date
org_groups
ColumnTypeDescription
group_idPKINTPrimary key for the org group
group_nameVARCHAR(255)Group or department name
surfaceVARCHAR(50)Meta surface, for example fb groups or ig reels
Tablesemployeesorg_groups
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results