這種單表比較條件,一般都是表內進行 操作. 參照此思路,解題如下所示: 運行效率在可以接受的範圍,此外語句也較為清晰便於維護. ...
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 |
+----------+
這種單表比較條件,一般都是表內進行join
操作.
參照此思路,解題如下所示:
# Write your MySQL query statement below
SELECT
a.Name AS Employee
FROM Employee a, Employee b
WHERE
a.ManagerId = b.Id
AND a.Salary > b.Salary;
運行效率在可以接受的範圍,此外語句也較為清晰便於維護.