Highest paid in each department

subqueries

Highest paid in each department

Meta SQL Interview Question

As part of Meta's annual pay review, the compensation team wants to see the top earner in every department.

Find the highest paid employee in each department, showing their department, name and salary. If two people in the same department share the top salary, return both.

Asked of

  • Data Analyst
  • Data Scientist
  • Analytics Engineer
  • Data Engineer

employeesTable16 rows

Column NameType
employee_idBIGINT
nameVARCHAR
departmentVARCHAR
salaryBIGINT
manager_idBIGINT
hire_dateDATE

employeesExample Input

employee_idnamedepartmentsalarymanager_idhire_date
1Ravi KumarExecutive240000NULL2018-01-15
2Mei LinEngineering18500012018-06-04
3Sofia RossiEngineering14200022019-02-18
4James ParkEngineering12800022019-09-02
7Diego AlvarezAnalytics16800012018-10-22
8Hannah WeberAnalytics13400072020-01-13

Example Output

departmentnamesalary
AnalyticsDiego Alvarez168000
EngineeringMei Lin185000
ExecutiveRavi Kumar240000

Explanation

Mei Lin earns 185,000, the most in Engineering, and Diego Alvarez earns 168,000, the most in Analytics. Ravi Kumar is the only person in Executive, so Ravi Kumar is its top earner.

The example above is a small slice of the data. Your query runs against the full tables.