Department Top-3 Earners
Problem
**[Widely asked at FAANG companies]**
A "high earner" is an employee whose salary is in the **top 3 within their department**.
Ties count — if 4 employees are tied for 3rd place, all 4 are high earners.
For every high earner, return `department_name`, `employee_name`, and `salary`,
ordered by department then salary descending.
Tables
Example rows — the live problem includes the full dataset.
staff
| emp_id | emp_name | salary | dept_id |
|---|
departments
| dept_id | dept_name |
|---|
Expected output
Your answer should return 10 rows with the columns dept_name, emp_name, salary.
Starter code (SQL)
SELECT *
FROM staff;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock