欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > 力扣之181.超过经理收入的员工

力扣之181.超过经理收入的员工

2025/4/19 14:03:32 来源:https://blog.csdn.net/m0_70882914/article/details/142341853  浏览:    关键词:力扣之181.超过经理收入的员工

文章目录

  • 1. 181.超过经理收入的员工
    • 1.1 题干
    • 1.2 准备数据
    • 1.3 题解
    • 1.4 结果截图

1. 181.超过经理收入的员工

1.1 题干

表:Employee

±------------±--------+
| Column Name | Type |
±------------±--------+
| id | int |
| name | varchar |
| salary | int |
| managerId | int |
±------------±--------+
id 是该表的主键(具有唯一值的列)。
该表的每一行都表示雇员的ID、姓名、工资和经理的ID。

编写解决方案,找出收入比经理高的员工。

以 任意顺序 返回结果表。

结果格式如下所示。

示例 1:

输入:
Employee 表:
±—±------±-------±----------+
| id | name | salary | managerId |
±—±------±-------±----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | Null |
| 4 | Max | 90000 | Null |
±—±------±-------±----------+
输出:
±---------+
| Employee |
±---------+
| Joe |
±---------+
解释: Joe 是唯一挣得比经理多的雇员。

1.2 准备数据

Create table If Not Exists Employee (id int, name varchar(255), salary int, managerId int)
Truncate table Employee
insert into Employee (id, name, salary, managerId) values ('1', 'Joe', '70000', '3')
insert into Employee (id, name, salary, managerId) values ('2', 'Henry', '80000', '4')
insert into Employee (id, name, salary, managerId) values ('3', 'Sam', '60000', NULL)
insert into Employee (id, name, salary, managerId) values ('4', 'Max', '90000', NULL)

1.3 题解

# 解法一
select e1.name Employeefrom employee e1 join employee e2on e2.id = e1.managerIdand e1.salary>e2.salary;# 解法二
select name as Employee from Employee e where salary>(select salary from Employee where id=e.managerId)

1.4 结果截图

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词