考试的一个题,做不到呀~~!大家帮忙下

mxzy55560593 2009-04-01 10:18:31
雇员表

职工号 职工姓名 职位 经理号 工资 部门号
7369 a 办事员 7902 80 20
7499 b 办事员 7698 160 30
7521 c 办事员 7698 125 30
7566 d 部门经理 7839 297 20
7654 e 办事员 7698 125 30
7698 f 部门经理 7839 285 30
7782 g 部门经理 7839 245 10
7788 h 办事员 7566 300 20
7839 i 总经理 500 10
7844 j 办事员 7698 150 30
...
要求查询 找出工资超过经理的职工,列出姓名 工资及其经理的姓名和工资
谢啦
...全文
180 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ai_li7758521 2009-04-02
  • 打赏
  • 举报
回复
select a.职工姓名, a.工资 ,经理=b.职工姓名,经理工资=b.工资
from tb2 a join tb2 b
on a.经理号 =b.职工号 and a.工资> b.工资

/*
职工姓名 工资 经理 经理工资
------------ ----------- -------- -----------
h 300 d 297
(1 行受影响)
*/
mugua604 2009-04-01
  • 打赏
  • 举报
回复

SELECT a.*,b.职位,b.职工姓名,b.工资
from 雇员表 a
left join 雇员表 b ON a. 部门号= b. 部门号 AND b.经理号 ='7839
where a.工资 >=b.工资


mugua604 2009-04-01
  • 打赏
  • 举报
回复


SELECT a.*,b.职位,b.职工姓名,b.工资
from 雇员表 a
left join 雇员表 b ON a. 部门号= b. 部门号 AND b.职位 ='部门经理'
where a.工资 >=b.工资

small_well 2009-04-01
  • 打赏
  • 举报
回复
[Quote]

select * from tb where 工资> (select max(工资) from tb where 职位='部门经理')
[/Quote]
幸运的意外 2009-04-01
  • 打赏
  • 举报
回复
declare @tb table (Eid int, Ename varchar(2), Elevel nvarchar(10), Eleaderid int, Esalary int, Edept int)
insert @tb select 7369 ,'a', N'办事员', 7902, 80, 20
union all select 7499 ,'b', N'办事员', 7698, 160, 30
union all select 7521 ,'c', N'办事员', 7698, 125, 30
union all select 7566 ,'d', N'部门经理', 7839, 297, 20
union all select 7654 ,'e', N'办事员', 7698, 125, 30
union all select 7698 ,'f', N'部门经理', 7839, 285, 30
union all select 7782 ,'g', N'部门经理', 7839, 245, 10
union all select 7788 ,'h', N'办事员', 7566, 300, 20
union all select 7839 ,'i', N'总经理', null, 500, 10
union all select 7844 ,'j', N'办事员', 7698, 150, 30

select E.Eid, E.Esalary ,M.Eid, M.Esalary
from
@tb E
left outer join
@tb M
on
E.Edept = M.Edept
and
E.Eleaderid = M.Eid
where
E.Esalary > M.Esalary
jwdream2008 2009-04-01
  • 打赏
  • 举报
回复
if object_id('tb') is not null
drop table tb
go
create table tb(职工号 varchar(10),职工姓名 varchar(10),职位 varchar(10),经理号 varchar(10),工资 int,部门号 varchar(10))
go

insert into tb
select '7369' , 'a' , '办事员' , '7902' ,80 , '20' union all
select
'7499' , 'b' , '办事员' , '7698' ,160 ,'30' union all
select
'7521', 'c' , '办事员' , '7698' , 125 , '30' union all
select
'7566' , 'd' , '部门经理', '7839' , 297 ,'20' union all
select
'7654' , 'e' , '办事员' , '7698' , 125 , '30' union all
select
'7698' , 'f' , '部门经理', '7839' , 285 ,'30' union all
select
'7782' , 'g' , '部门经理' ,'7839' , 245 , '10' union all
select
'7788', 'h' , '办事员' , '7566' ,300, '20' union all
select
'7839' , 'i' , '总经理' , '' , 500 , '10' union all
select
'7844' , 'j' , '办事员', '7698', 150 , '30'
go

select a.职工姓名,a.工资,b.职工姓名 as 经理姓名,b.工资 as 经理工资 from tb a left join tb b on a.经理号=b.职工号 where a.工资>b.工资

Teng_s2000 2009-04-01
  • 打赏
  • 举报
回复

select * from tb
go
select * from tb where 工资>
(
select max(工资) from tb where 职位='部门经理'
)
  • 打赏
  • 举报
回复
--> (让你望见影子的墙)生成测试数据,时间:2009-04-01

if not object_id('tb2') is null
drop table tb2
Go
Create table tb2([职工号] Datetime,[职工姓名] nvarchar(1),[职位] nvarchar(4),[经理号] int,[工资] int,[部门号] int)
Insert tb2
select '7369',N'a',N'办事员',7902,80,20 union all
select '7499',N'b',N'办事员',7698,160,30 union all
select '7521',N'c',N'办事员',7698,125,30 union all
select '7566',N'd',N'部门经理',7839,297,20 union all
select '7654',N'e',N'办事员',7698,125,30 union all
select '7698',N'f',N'部门经理',7839,285,30 union all
select '7782',N'g',N'部门经理',7839,245,10 union all
select '7788',N'h',N'办事员',7566,300,20 union all
select '7839',N'i',N'总经理',500,10,null union all
select '7844',N'j',N'办事员',7698,150,30
Go
Select * from tb2

大于所有部门经理的
select * from tb2
where 职位<>'部门经理' and 工资> all(select 工资 from tb2 where 职位='部门经理' )

职工号 职工姓名 职位 经理号 工资 部门号
7788-01-01 00:00:00.000 h 办事员 7566 300 20

大于其中一个就可以的

select * from tb2
where 职位<>'部门经理' and 工资> some(select 工资 from tb2 where 职位='部门经理' )
  • 打赏
  • 举报
回复
找出工资超过经理的职工

因为经理的工资不一样,要求是大于所有经理工资的还是只要大于其中的一个就可以了?
lg3605119 2009-04-01
  • 打赏
  • 举报
回复

if object_id('tb') is not null
drop table tb
go
create table tb(职工号 varchar(10),职工姓名 varchar(10),职位 varchar(10),经理号 varchar(10),工资 int,部门号 varchar(10))
go

insert into tb
select '7369' , 'a' , '办事员' , '7902' ,80 , '20' union all
select
'7499' , 'b' , '办事员' , '7698' ,160 ,'30' union all
select
'7521', 'c' , '办事员' , '7698' , 125 , '30' union all
select
'7566' , 'd' , '部门经理', '7839' , 297 ,'20' union all
select
'7654' , 'e' , '办事员' , '7698' , 125 , '30' union all
select
'7698' , 'f' , '部门经理', '7839' , 285 ,'30' union all
select
'7782' , 'g' , '部门经理' ,'7839' , 245 , '10' union all
select
'7788', 'h' , '办事员' , '7566' ,300, '20' union all
select
'7839' , 'i' , '总经理' , '' , 500 , '10' union all
select
'7844' , 'j' , '办事员', '7698', 150 , '30'
go

select a.*,b.职工姓名 as 经理姓名 from
(select a.*,部门经理工资=(select max(工资) from tb where 职工号=a.经理号) from tb a)a
left join tb b on a.经理号=b.职工号
where a.工资>a.部门经理工资

drop table tb

22,211

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧