chengchengxu15 / CS-leaning

1 stars 1 forks source link

181. Employees Earning More Than Their Managers #67

Open chengchengxu15 opened 2 years ago

chengchengxu15 commented 2 years ago

image

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', 'None')
insert into Employee (id, name, salary, managerId) values ('4', 'Max', '90000', 'None')
chengchengxu15 commented 2 years ago
SELECT a.name as Employee
FROM Employee a
JOIN Employee b
ON a.managerId = b.id 
WHERE a.salary > b.salary;
chengchengxu15 commented 2 years ago

要想到读两次同一个表,小技巧记住就好