2020-04-09-(02)

给定 Employee 表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名。在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。

Screen Shot 2020-04-09 at 9.53.03 PM.png

Solution 1

Select E1.Name as Employee
From Employee as E1, Employee as M2
Where M2.Id=E1.ManagerId And E1.Salary > M2.Salary

Solution 2

SELECT
     a.NAME AS Employee
FROM Employee AS a JOIN Employee AS b
     ON a.ManagerId = b.Id
     AND a.Salary > b.Salary

表A经理的ID=表B员工的ID,且表A的工资大于表B的工资

你可能感兴趣的:(2020-04-09-(02))