【简单】181. 超过经理收入的员工

643 篇文章 5 订阅

【题目】
Employee 表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。给定 Employee 表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名Name。
Employee表头 Id | Name | Salary | ManagerId
在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。
来源:leetcode
链接:https://leetcode-cn.com/problems/employees-earning-more-than-their-managers/
【代码】
【join大法好】效率非常优秀了
执行用时 :257 ms, 在所有 MySQL 提交中击败了95.19% 的用户
内存消耗 :0B, 在所有 MySQL 提交中击败了100.00%的用户

# Write your MySQL query statement below
select a.Name as Employee from Employee as a join Employee as bon a.ManagerId=b.Id and a.Salary>b.Salary

【一个select】
执行用时 :280 ms, 在所有 MySQL 提交中击败了63.02% 的用户
内存消耗 :0B, 在所有 MySQL 提交中击败了100.00%的用户

# Write your MySQL query statement below
select a.Name as Employee from Employee a,Employee b 
where a.ManagerId=b.Id and a.Salary>b.Salary

【两个select】这个很慢

# Write your MySQL query statement below
select Name as Employee from Employee a where ManagerId and Salary > 
(select Salary from Employee b where a.ManagerId=b.Id)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值