181. Employees Earning More Than Their Manage…

2018-06-18 00:59:16来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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

 


 

 

Solution:

Select E1.name as Employee from
Employee as E1, Employee as E2
where E1.ManagerId = E2.Id and E1.Salary > E2.Salary;

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:数据库之mysql篇(5)—— 【转载】mysql练习题

下一篇:mysql 中 innoDB 与 MySAM