Skip to content

Commit 4352421

Browse files
committed
AMZN 181
1 parent c70f575 commit 4352421

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Problem: 181. Employees Earning More Than Their Managers
2+
3+
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
4+
5+
+----+-------+--------+-----------+
6+
| Id | Name | Salary | ManagerId |
7+
+----+-------+--------+-----------+
8+
| 1 | Joe | 70000 | 3 |
9+
| 2 | Henry | 80000 | 4 |
10+
| 3 | Sam | 60000 | NULL |
11+
| 4 | Max | 90000 | NULL |
12+
+----+-------+--------+-----------+
13+
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.
14+
15+
+----------+
16+
| Employee |
17+
+----------+
18+
| Joe |
19+
+----------+
20+
21+
--------------------------------------------------------------------------------------------------------------------------------------
22+
Solution 1:
23+
24+
SELECT e.name Employee FROM Employee AS e, Employee AS e1
25+
WHERE e.ManagerId = e1.Id AND e.Salary > e1.Salary;
26+
27+
-----------------------------------------------------------------
28+
29+
Solution 2:
30+
31+
Select emp.Name from Employee emp
32+
inner join Employee manager on emp.ManagerId = manager.Id
33+
where emp.Salary > manager.Salary
34+
35+
--------------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)