Open chengchengxu15 opened 2 years ago
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')
SELECT a.name as Employee FROM Employee a JOIN Employee b ON a.managerId = b.id WHERE a.salary > b.salary;
要想到读两次同一个表,小技巧记住就好