EASY
Employees Whose Manager Left the Company
Each row of this table indicates that the employee with id id has a manager with id managerId. If managerId is null, that employee has no manager.
Write an SQL query to report the number of employees who will remain in the company after all possible departures (if an employee's manager leaves, the employee also leaves).
Solution: SQL
SELECT e1.employee_id
FROM Employees e1
LEFT JOIN Employees e2
ON e1.manager_id = e2.employee_id
WHERE e1.salary < 30000 AND e2.employee_id IS NULL AND e1.manager_id IS NOT NULL
ORDER BY employee_id;