
Highest paid in each department
hardHighest 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 Name | Type |
|---|---|
| employee_id | BIGINT |
| name | VARCHAR |
| department | VARCHAR |
| salary | BIGINT |
| manager_id | BIGINT |
| hire_date | DATE |
employeesExample Input
| employee_id | name | department | salary | manager_id | hire_date |
|---|---|---|---|---|---|
| 1 | Ravi Kumar | Executive | 240000 | NULL | 2018-01-15 |
| 2 | Mei Lin | Engineering | 185000 | 1 | 2018-06-04 |
| 3 | Sofia Rossi | Engineering | 142000 | 2 | 2019-02-18 |
| 4 | James Park | Engineering | 128000 | 2 | 2019-09-02 |
| 7 | Diego Alvarez | Analytics | 168000 | 1 | 2018-10-22 |
| 8 | Hannah Weber | Analytics | 134000 | 7 | 2020-01-13 |
Example Output
| department | name | salary |
|---|---|---|
| Analytics | Diego Alvarez | 168000 |
| Engineering | Mei Lin | 185000 |
| Executive | Ravi Kumar | 240000 |
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.
Company
Meta
Difficulty
hard
Topic
subqueries
Your query
Starting the SQL engine...