181超过经理收入的员工
181 工资超过经理的员工
表:Employee
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
| salary | int |
| managerId | int |
+-------------+---------+
id 是该表的主键(具有唯一值的列)。
该表的每一行都表示雇员的ID、姓名、工资和经理的ID。
编写解决方案,找出收入比经理高的员工。
以 任意顺序 返回结果表。
结果格式如下所示。
示例 1:
<strong>输入:</strong>
Employee 表:
+----+-------+--------+-----------+
| id | name | salary | managerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | Null |
| 4 | Max | 90000 | Null |
+----+-------+--------+-----------+
<strong>输出:</strong>
+----------+
| Employee |
+----------+
| Joe |
+----------+
<strong>解释:</strong> Joe 是唯一挣得比经理多的雇员。
-- 创建表
create table Employee (
id int IDENTITY(1,1) primary key,
name varchar(50),
salary int,
managerId int
)
go
--插入数据
insert into Employee values('Joe','7000',3);
insert into Employee values('Henry','8000',4);
insert into Employee values('Sam','6000',null);
insert into Employee values('Max','9000',null);
--解题 ms sql server
select temp.name Employee
from
(
select e1.name,e1.salary e1_s,e2.salary m_s
from Employee e1
inner join
Employee e2
on e1.managerId=e2.id
) as temp
where temp.e1_s>temp.m_s
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性