-
Notifications
You must be signed in to change notification settings - Fork 0
/
employeesmanagers.sql
38 lines (28 loc) · 957 Bytes
/
employeesmanagers.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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:
+----+-------+--------+-----------+
| id | name | salary | managerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | Null |
| 4 | Max | 90000 | Null |
+----+-------+--------+-----------+
Output:
+----------+
| Employee |
+----------+
| Joe |
+----------+
Explanation: Joe is the only employee who earns more than his manager.
/*select A.name as Employee from
(select id,name,salary,managerId from Employee)A
join
(select id,name,salary,managerId from Employee)B
ON A.managerId=B.id and A.salary>B.salary*/
select c.* from
(select a.Name as "Employee" from Employee as a, Employee as b where a.ManagerId = b.Id and a.Salary > b.Salary)c