Employees Who Earn More Than Their Managers
Problem statement
The employees table has one row per employee, with their salary and the ID of their direct manager.
Return the employee_id and employee_name of every employee who earns more than their direct manager. Sort the rows by employee_id from smallest to largest.
- A
nullmanager_idmeans the employee has no manager, so they are left out. - An employee who earns exactly as much as their manager is left out.
- Compare only with the direct manager, not with anyone higher up.
- Two employees can have the same name. They are still different employees.
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 and the ID of their direct manager.
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | — |
| employee_name | Text | No | — |
| salary | Integer | No | — |
| manager_id | Integer | Yes | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_id | Integer | No | — |
| employee_name | Text | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The table has at most
2000rows. employee_idis unique and between1and10^9.employee_nameis non-empty text of at most100characters.salaryis an integer between0and10^9.- Every non-null
manager_idis theemployee_idof another row. Nobody is their own manager, and the reporting lines have no cycles.