Find the names of employees in the Engineering department who earn more than their manager. manager_id references another employee, possibly in a different department. Return a single column Employee, ordered by employee name ascending.
Input Table(s)
Table: departments
| Column | Type | Meaning |
|---|
| id | INT | Department identifier (primary key) |
| name | VARCHAR(100) | Department name, not null |
Table: employees
| Column | Type | Meaning |
|---|
| id | INT | Employee identifier (primary key) |
| name | VARCHAR(100) | Employee name, not null, not necessarily unique |
| salary | INT | Employee salary, not null |
| department_id | INT | The employee's department (foreign key to departments.id) |
| manager_id | INT | The employee's manager (foreign key to employees.id), NULL for top-level employees |
Keys: departments.id and employees.id are primary keys. employees.department_id references departments.id, and employees.manager_id references employees.id.
Output Contract
-
One column named
Employee
, holding the employee's
name
.
-
One row per qualifying employee. Two different employees with the same name both appear.
-
Sort by
Employee
ascending, then by the employee's
id
ascending so that equal names have a fixed order.
-
No rounding is involved.
Example
departments
employees
| id | name | salary | department_id | manager_id |
|---|
| 1 | Alice | 90000 | 1 | NULL |
| 2 | Bob | 100000 | 1 | 1 |
| 3 | Charlie | 80000 | 1 | 1 |
| 4 | Diana | 95000 | 2 | 1 |
Expected output:
Bob works in Engineering and earns 100000, which is more than his manager Alice (90000). Charlie works in Engineering but earns less than Alice. Diana earns more than Alice but is in Sales, not Engineering. Alice has no manager, so there is nothing to compare her against.
Constraints and Clarifications
-
employees
has at most 10,000 rows and
departments
at most 100 rows.
-
salary
is a non-negative integer and is never NULL.
-
manager_id
is NULL for top-level employees. They have no manager and are not returned.
-
"More than" is strict. An employee who earns exactly the manager's salary is not returned.
-
Only the employee has to be in Engineering. The manager can be in any department.
-
An employee is in Engineering when the
name
of their department is exactly
'Engineering'
.
-
Employee names are not unique. Do not merge two employees who share a name.