[LeetCode] 181. Employees Earning More Than Their Managers

Problem

The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

IdNameSalaryManagerId
1Joe700003
2Henry800004
3Sam60000NULL
4Max90000NULL

Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.

Employee
Joe

Solution

select e.Name as "Employee" from Employee e 
join Employee m 
on (e.ManagerId = m.Id) 
where e.Salary > m.Salary; 
    原文作者:linspiration
    原文地址: https://segmentfault.com/a/1190000017519190
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞