[LeetCode MySQL] 181. Employees Earning More Than Their Managers
2021. 1. 11. 23:32ㆍToday I Learned.../MySQL
181. Employees Earning More Than Their Managers
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 |
+----------+
QUERY
select e.name Employee
from employee e inner join employee m
on e.ManagerId = m.id
where e.salary > m.salary
Reference: 197. Rising Temperature
'Today I Learned... > MySQL' 카테고리의 다른 글
[LeetCode MySQL] 180. Consecutive Numbers (0) | 2021.01.19 |
---|---|
[HackerRank MySQL] Symmetric Pairs (0) | 2021.01.11 |
[LeetCode MySQL] 197. Rising Temperature (0) | 2021.01.11 |
[LeetCode MySQL] 183. Customers Who Never Order (0) | 2021.01.11 |
[LeetCode MySQL] 1179. Reformat Department Table (0) | 2021.01.11 |