Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top N by Group Salary

EasySQL · 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

Given two tables, list the top N people with the highest salary in a specific group/department (SQL or Pandas option).

Asked in the Technical Phone Screen stage. Choice between SQL or Pandas was allowed. Standard top-N aggregation across two tables.

Task

Write a SQL query to return the top N people by salary for one specific Meta department, such as Instagram Reels.

Requirements

  1. Join the employee table to the department table.
  2. Filter to the target department name.
  3. Rank people by salary descending, with employee_id as the tie-breaker.
  4. Return only the top N rows.

Output

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee full name
department_idINTReferences departments.department_id
salaryNUMERIC(12,2)Annual salary in USD
departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department or group name
Tablesemployeesdepartments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results