Loading problem...
Your analytics team tracks compensation across business units.
You are given two relational tables:
id, name, salary, departmentId)id, name)Build a result set that returns every employee whose salary is the highest within their own department.
Important rules:
Employee.departmentId = Department.id).DepartmentEmployeeSalaryUnless your local evaluator requires deterministic ordering, rows may be returned in any order.
This problem should be solvable in both:
Employee:
| id | name | salary | departmentId |
|----|-------|--------|--------------|
| 1 | Joe | 70000 | 1 |
| 2 | Jim | 90000 | 1 |
| 3 | Henry | 80000 | 2 |
| 4 | Sam | 60000 | 2 |
| 5 | Max | 90000 | 1 |
Department:
| id | name |
|----|-------|
| 1 | IT |
| 2 | Sales |[
{"Department":"IT","Employee":"Jim","Salary":90000},
{"Department":"IT","Employee":"Max","Salary":90000},
{"Department":"Sales","Employee":"Henry","Salary":80000}
]IT has a top-salary tie at 90000, so both Jim and Max are returned. Sales has a single top earner, Henry.
Employee:
| id | name | salary | departmentId |
|----|--------|--------|--------------|
| 10 | Alice | 120000 | 3 |
| 11 | Bob | 95000 | 3 |
Department:
| id | name |
|----|------------|
| 3 | Marketing |
| 4 | Legal |[
{"Department":"Marketing","Employee":"Alice","Salary":120000}
]Only Marketing has employees in this input. Legal has no employees, so it contributes no output row.
Employee:
| id | name | salary | departmentId |
|----|-------|--------|--------------|
| 21 | Emma | 50000 | 7 |
| 22 | Emma | 70000 | 8 |
| 23 | Noah | 70000 | 8 |
Department:
| id | name |
|----|-----------|
| 7 | Support |
| 8 | Support |[
{"Department":"Support","Employee":"Emma","Salary":50000},
{"Department":"Support","Employee":"Emma","Salary":70000},
{"Department":"Support","Employee":"Noah","Salary":70000}
]Departments are separated by ID, even when names are the same. Department 7 has top salary 50000, while department 8 has top salary 70000 with a tie.
Constraints