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')
+----+-------+--------+-----------+ | Id | Name | Salary | ManagerId | +----+-------+--------+-----------+ | 1 | Joe | 70000 | 3 | | 2 | Henry | 80000 | 4 | | 3 | Sam | 60000 | NULL | | 4 | Max | 90000 | NULL | +----+-------+--------+-----------+
+----------+ | Employee | +----------+ | Joe | +----------+
select
a.Name as 'Employee'
from employee as a, employee as b
where a.`ManagerId`=b.`Id` and a.`Salary`>b.`Salary`
Runtime: 320 ms, faster than 52.18% of MySQL online submissions forEmployees Earning More Than Their Managers.
Memory Usage: N/A
Runtime: 299 ms, faster than 83.22% of MySQL online submissions forEmployees Earning More Than Their Managers.
Memory Usage: N/A
Runtime: 336 ms, faster than 43.06% of MySQL online submissions forEmployees Earning More Than Their Managers.
Memory Usage: N/A
Runtime: 311 ms, faster than 63.59% of MySQL online submissions forEmployees Earning More Than Their Managers.
Memory Usage: N/A
Runtime: 289 ms, faster than 95.16% of MySQL online submissions forEmployees Earning More Than Their Managers.
Memory Usage: N/A