LeetCode (181) - more than the manager of employee input

topic:

Employee table contains all employees, their managers belong to employees. Each employee has a Id, in addition to a correspondence Id manager of staff.

± - ± ± ------- ------ ± ---------- +
| Id | the Name | the 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 you can earn money more than their manager the employee's name. In the above table, Joe is the only one earning more than his manager's staff.

±---------+
| Employee |
±---------+
| Joe |
±---------+

answer:

This question relates to the query with a table comparing the two data, thus requiring the same table to connect multiple comparison.
The comparison of this problem, the use of the appropriate connector, which can filter out null entries.

select e1.Name as Employee from Employee e1 inner join Employee e2 on e1.ManagerId=e2.Id where e1.Salary>e2.Salary;

Guess you like

Origin blog.csdn.net/Fly_Fly_Zhang/article/details/95319842