【LeetCode】MySQL:数据库简单题(181)

181 超过经理收入的员工

(1)题目描述

【LeetCode】MySQL:数据库简单题(181)_第1张图片【LeetCode】MySQL:数据库简单题(181)_第2张图片

(2)具体实现

# Write your MySQL query statement below
# 法一:子查询 (执行时间 905 ms)
# select name as Employee from Employee e
# where e.salary > (
#     select salary from Employee t
#     where t.id = e.managerId)
# # 法二:自连接 (执行时间 246 ms)
# select e.name as Employee 
# from Employee e, Employee t
# where e.managerId = t.id and e.salary > t.salary
# 法三:自连接-join on (执行时间 381 ms)
select e.name as Employee 
from Employee e join Employee t
on e.managerId = t.id and e.salary > t.salary

(3)总结

  • 子查询如何嵌套及相应的嵌套关系没理清楚
  • 自连接两个表哪个是主体也没理清楚
  • 大概知道怎么做,但具体语句还有待掌握

你可能感兴趣的:(LeetCode,数据库,mysql,leetcode)