编辑代码

CREATE DATABASE test;
use test;

CREATE TABLE Employee (
    id int,
    name varchar(255),
    salary int,
    managerId int
);

insert into Employee values(1,'Joe',70000,3);
insert into Employee values(2,'Henry',80000,4);
insert into Employee values(3,'Sam',60000,null);
insert into Employee values(4,'Max',90000,null);
# 思路:做一个左连接,左表员工的经理id连接右表的员工id得到每行有右表就是经理,判断左表员工是否大于右表经理的工资
select t1.name Employee
from Employee t1 left join Employee t2
on t1.managerId=t2.id 
where t1.salary>t2.salary;