The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
+----+-------+--------+-----------+ | Id | Name | Salary | ManagerId | +----+-------+--------+-----------+ | 1 | Joe | 70000 | 3 | | 2 | Henry | 80000 | 4 | | 3 | Sam | 60000 | NULL | | 4 | Max | 90000 | NULL | +----+-------+--------+-----------+
Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.
+----------+ | Employee | +----------+ | Joe | +----------+
select e.Name as Employee
from Employee as e, Employee as m
where e.ManagerId is not NULL and
e.ManagerId = m.ID and e.Salary > m.Salary

本文探讨了一个有趣的SQL查询挑战,旨在从员工表中筛选出那些薪资超过其直接上司的员工。通过对比员工与其上司的薪资,我们能够找出这种独特的薪资倒挂现象。以一个具体的例子进行说明,展示了如何使用SQL查询来实现这一目标。
1665

被折叠的 条评论
为什么被折叠?



