【LeetCode】181. Employees Earning More Than Their Managers

来源:互联网 发布:淘宝店托管 编辑:程序博客网 时间:2024/05/21 19:45

1、题目要求: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.

解答:

1)SELECT e1.Name AS Employee
   FROM Employee AS e1 INNER JOIN Employee AS e2
   ON e1.ManagerId = e2.Id
   WHERE e1.Salary > e2.Salary

2) 或者用两个条件进行过滤

SELECT a.NAME FROM Employee a, Employee b 

WHERE a.ManagerId = b.Id AND a.Salary > b.Salary;

注,AS 用作别名,可写可不写。


原创粉丝点击