Well Paid Employees
Beginner Mode
Objective
Write a SQL query to find employees who earn more than their direct managers.
Table Schema:
- employees
| Column | Type | Description |
|---|---|---|
| employee_id | INTEGER | Unique identifier for each employee |
| employee_name | VARCHAR | Name of the employee |
| salary | INTEGER | Employee's salary |
| manager_id | INTEGER | ID of the employee's direct manager (NULL for top-level employees) |
Task Requirements:
- Compare each employee's salary with their manager's salary
- Find employees whose salary is greater than their manager's salary
- Output employee ID and name
- Sort results by employee ID in ascending order
Output columns: employee_id, employee_name
Examples
Example 1:
Output:
Input:
| employees | |||
|---|---|---|---|
| employee_id | employee_name | manager_id | salary |
| 1 | Alice | null | 80000 |
| 2 | Bob | 1 | 70000 |
| 3 | Charlie | 1 | 90000 |
| 4 | David | 2 | 60000 |
| 5 | Eve | 2 | 75000 |
| employee_id | employee_name |
|---|---|
| 3 | Charlie |
| 5 | Eve |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Meta