leetcode181 than income managers employees Employees Earning More Than Their Managers

EmployeeThe following table contains all employees, including their managers. Each employee has a Id , in addition to a corresponding manager Id .

Creating tables and data:

drop table Employee
Create
table If Not Exists Employee (Id int, Name varchar(255), Salary int, ManagerId int); Truncate table Employee; insert into Employee (Id, Name, Salary,ManagerId) values ('1', 'Joe', '70000', '3'); insert into Employee (Id, Name, Salary,ManagerId) values ('2', 'Henry', '80000', '4'); insert into Employee (Id, Name, Salary,ManagerId) values ('3', 'Sam', '60000', Null); insert into Employee (Id, Name, Salary,ManagerId) values ('4', 'Max', '90000', Null);

solution:

1. Since the connection table, identify each employee's manager, screened salary higher than the salaries of the staff manager.

select E1.Name as Employee
from Employee as E1 join Employee as E2 on (E1.ManagerId  = E2.Id and E1.salary > E2.salary)

 

Guess you like

Origin www.cnblogs.com/forever-fortunate/p/11722830.html