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
标签:salary,name,int,经理,员工,181,Employee,e1,id
From: https://www.cnblogs.com/BenYiCore/p/18131788