前言
持续更新了
正文
问题来源
本问题来自leetcode上的181题。
问题描述
Employee 表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。 表结构与数据
+----+-------+--------+-----------+
| 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 a, Employee b where a.ManagerId = b.Id and a.Salary > b.Salary;
总结:
勤思考。
结语
不管怎么样好好加油。