๐ธ When the Apprentice Earns More Than the Master.
It started as a whisper in the corridors of Google's People Analytics team. Someone claimed that several employees were earning more than their direct managers. HR dismissed it. The data will settle it.
Find all employees who earn a strictly higher salary than their direct manager. Return the employee's name, their salary, their manager's name, and their manager's salary. Order by the salary gap descending.
This is a self-join problem. The employees table contains both employees and managers โ you need to join the table to itself on the manager_id relationship.
employees Table:
| Column | Type |
|---|---|
| employee_id | integer |
| name | text |
| department | text |
| salary | integer |
| manager_id | integer (NULL for top-level) |
Expected Outcome (Illustrative Sample):
| employee_name | employee_salary | manager_name | manager_salary | salary_gap |
|---|---|---|---|---|
| Sanjay G | 340000 | Prabhakar R | 320000 | 20000 |
The numbers don't lie. Find the paradox.