SQL data engineering interview problem. Difficulty: beginner. Pattern: Self Joins. About 8 minutes. Part of the Pro drill bank.
org_staff stores each person's manager_id, which points to another row in the same table. Return every employee whose salary is strictly greater than their manager's salary. Columns: employee_name, employee_salary, manager_name, manager_salary. Order by employee_id.
Input: org_staff employee_id | name | salary | manager_id 1 | Priya | 150000 | NULL 2 | Quinn | 160000 | 1 3 | Ravi | 90000 | 1 4 | Sia | 95000 | 3 5 | Tom | NULL | 1 6 | Uma | 90000 | 3 7 | Vik | 70000 | 9 Output: employee_name | employee_salary | manager_name | manager_salary Quinn | 160000 | Priya | 150000 Sia | 95000 | Ravi | 90000 Why this passes: Quinn earns more than Priya and Sia earns more than Ravi. Uma ties with Ravi, Tom has no salary, and Vik's manager row does not exist.
Input: org_staff employee_id | name | salary | manager_id 1 | Boss | 100 | NULL 2 | Ann | 120 | 1 3 | Ben | 80 | 1 Output: employee_name | employee_salary | manager_name | manager_salary Ann | 120 | Boss | 100 Why this passes: One employee out-earns the manager and one does not.
Topics: lakebench, sql, self join, manager.
More SQL interview questions · All interview problems · Learn data engineering
Interview-style drill: Find employees paid more than the person they report to.
`org_staff` stores each person's `manager_id`, which points to another row in the same table. Return every employee whose `salary` is strictly greater than their manager's `salary`. Columns: `employee_name`, `employee_salary`, `manager_name`, `manager_salary`. Order by `employee_id`.