关闭

181. Employees Earning More Than Their Managers

80人阅读 评论(0) 收藏 举报
分类:

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

+----+-------+--------+-----------+
| Id | Name  | Salary | ManagerId |
+----+-------+--------+-----------+
| 1  | Joe   | 70000  | 3         |
| 2  | Henry | 80000  | 4         |
| 3  | Sam   | 60000  | NULL      |
| 4  | Max   | 90000  | NULL      |
+----+-------+--------+-----------+

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      |
+----------+

SELECT e1.Name AS Employee
FROM Employee e1,Employee e2
WHERE e1.Salary > e2.Salary 
AND e1.ManagerId = e2.Id;






0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:31142次
    • 积分:1389
    • 等级:
    • 排名:千里之外
    • 原创:116篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章分类