題目:
Table: Employee
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
| salary | int |
| managerId | int |
+-------------+---------+
id is the primary key column for this table.
Each row of this table indicates the ID of an employee, their name, salary, and the ID of their manager.
Write an SQL query to find the employees who earn more than their managers.
Return the result table in any order.
給定一個table,找到薪水比他們經理高的人
SELECT a.Name AS Employee
FROM Employee AS a JOIN Employee AS b
ON a.ManagerId = b.Id
AND a.Salary > b.Salary;
將該表(a表)跟另一個自己(b表)結合
條件設a表ManagerId等於b表的Id且a表的Salary大於b表的Salary
然後把a表的name選出就好
最後執行時間319ms(faster than 92.73%)
那我們下題見