#241
Highest Salary Per Department
MEDIUMSubqueriesPOSTGRESQL
Problem Description
You are a data engineer building an **HR analytics pipeline** that surfaces the top earner(s) in every department. Finance needs a daily snapshot: for each department, who holds the highest salary and what is it?
**Schema:**
- `departments`: `department_id` (PK), `department_name`.
- `employees`: `employee_id` (PK), `employee_name`, `department_id` (FK → departments), `salary` (positive integer).
**Key Rules:**
- Return **all** employees who share the maximum salary for their department — do not drop ties.
- Join `employees` to `departments` on `department_id` to resolve the department name.
- Output columns: `department_name`, `employee_name`, `salary`.
- Order by `salary` descending, then `department_name` ascending (deterministic sort for downstream consumers).
**Output:**
| department_name | employee_name | salary |
|----------------|--------------|--------|
| (string) | (string) | (integer) |
Topics
window functions
Asked at Companies
bytedance
Solve This Problem
Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.
Start Solving →