Table: Employee t-- ---- Column Namel Type t-- id name salary managerId --+- int varchar int 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. The query result format is in the following example Example 1: Input: Employee table: +----+-- ---+-- salary | managerId id name +------- 一+-- 1 Joe 70000 2 Henryl 80000 3 Sam 4Max 60000 C 90000 +-- -+- 3 14 Null Null -+ Output: +--- ---+ Employeel +----------+ Joe -- Explanation: Joe is the only employee who earns more than his manager.
时间: 2023-08-15 13:58:33 浏览: 163
go-pretty:漂亮的打印表,还有更多的golang内容!
你可以使用以下 SQL 查询来找到工资高于他们的经理的雇员:
```sql
SELECT e1.name AS Employee
FROM Employee e1
JOIN Employee e2 ON e1.managerId = e2.id
WHERE e1.salary > e2.salary;
```
这个查询使用了自连接(self join),通过将 `Employee` 表与自身进行连接,将每个雇员与他们的经理进行比较。然后,在 `WHERE` 子句中,筛选出工资高于其经理的雇员。
查询结果将返回一个结果表,其中包含满足条件的雇员的姓名。
希望这个查询能够满足你的需求!如果还有其他问题,请随时提问。
阅读全文