Problem · Database
Highest-Earning Employees By Department
Problem statement
The table employees stores one row per employee, including that employee's department and salary.
For each department, find its highest salary. Return every employee who earns that department-highest salary, including all employees tied at the top.
Return department_id, employee_id, employee_name, and salary. Order rows by department_id ascending, then employee_id ascending.
What the interview report shared
The interview report listed a SQL task about the highest-earning employee at the department level.
| Column | Meaning |
|---|---|
employee_id | Unique employee identifier |
employee_name | Employee display name |
department_id | Department identifier |
salary | Employee salary |
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
employees
One row per employee.
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | — |
| employee_name | Text | No | — |
| department_id | Integer | No | — |
| salary | Integer | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| department_id | Integer | No | — |
| employee_id | Integer | No | — |
| employee_name | Text | No | — |
| salary | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The
employeestable has between1and10^5rows. employee_idis unique and non-null.employee_name,department_id, andsalaryare non-null.0 <= salary <= 10^9.