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

posted on   关公  阅读(5)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示