LeetCode 181. Employees Earning More Than Their Managers 超过经理收入的员工(数据库)

题目:

LeetCode 181. Employees Earning More Than Their Managers 超过经理收入的员工(数据库)_第1张图片

解答:

解法一:

生成两个实例对象进行内交,通过比对ManagerId和Id,限制条件是一个Salary大于另一个即可

select Name Employee from Employee e1 where e1.Salary>
(select e2.Salary from Employee e2 where e1.ManagerId=e2.Id)

解法二:

通过 where 来实现

select a.Name as Employee
From Employee as a,Employee as b
where a.ManagerId=b.Id
and a.Salary>b.Salary;

或者使用 join 将两个表 a, b 连接起来,使用on指定条件

select a.Name as Employee
from Employee as a join Employee as b
     on a.ManagerId = b.Id
     and a.Salary > b.Salary;
     ```

你可能感兴趣的:(LeetCode)