---
# System prepended metadata

title: \#181 Employees Earning More Than Their Managers
tags: [leetcode, leetcode-easy, sql]

---

# \#181 Employees Earning More Than Their Managers
## *給定員工table, 找出薪資比其經理還高的員工(table內有從屬關係)*
## Log
 - build 20210417 by syhuang

## 子查詢(sub-query)
 - 效率較差
```sql=
select e1.Name as Employee
  from Employee e1
 where e1.Salary > (
     select e2.Salary 
       from Employee e2
      where e2.Id = e1.ManagerId)
```
## 初見
 - 簡單join關聯即可
```sql=
select e1.Name as Employee
  from Employee e1, Employee e2
 where e1.ManagerId = e2.Id
   and e1.Salary > e2.Salary
```
## 備註
## 參考
 - [3種ans:join/subquery/exists](https://leetcode.com/problems/employees-earning-more-than-their-managers/discuss/727229/MYSQL-or-3-different-ways-exists-join-subquery)
 - 
###### tags: `leetcode`, `leetcode-easy`, `sql`