Table: employees
+---------------+---------+ | Column Name | Type | +---------------+---------+ | employee_id | integer | | name | varchar | | salary | integer | | department_id | integer | | manager_id | integer | +---------------+---------+
employee_idis the primary key for this table.manager_idreferences theemployee_idof the direct manager; it isNULLfor top level managers.
Write a solution to identify all employees who earn more than their direct manager. Return the employee_id and name of each such employee.
Return the result table in any order. The result format is shown below.
Example
Input:
employees table: +-------------+------------------+--------+---------------+------------+ | employee_id | name | salary | department_id | manager_id | +-------------+------------------+--------+---------------+------------+ | 1 | Emma Thompson | 3800 | 1 | 6 | | 2 | Daniel Rodriguez | 2230 | 1 | 7 | | 3 | Olivia Smith | 7000 | 1 | 8 | | 4 | Noah Johnson | 6800 | 2 | 9 | | 5 | Sophia Martinez | 1750 | 1 | 11 | | 6 | Liam Brown | 13000 | 3 | NULL | | 7 | Ava Garcia | 12500 | 3 | NULL | | 8 | William Davis | 6800 | 2 | NULL | +-------------+------------------+--------+---------------+------------+Output:
+-------------+---------------+ | employee_id | employee_name | +-------------+---------------+ | 3 | Olivia Smith | +-------------+---------------+Explanation:
Olivia Smith (salary 7000) reports to William Davis (salary 6800). Since 7000 > 6800, Olivia is the only employee who earns more than her direct manager. Employees 4 and 5 reference manager IDs (9 and 11) that do not appear in the table, so those rows are dropped by the inner join.
Accepted
15/39
Acceptance Rate38.5%
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
-
Output
-
Expected
-