select * from 职工表 as me where not exists (select 1 from 职工表 where 部门 = me.部门 and 工资 > me.工资)
select * from 职工表 a where not exists(selec 1 from 职工表 where 部门 = a.部门 and 工资>a.工资)
select * from 职工表 where 职工号=(select top 1 职工号 from 职工表 order by 工资 desc)
select t.* from 职工表 t where not exists(select 1 from 职工表 where 部门 = t.部门 and 工资 > t.工资)select t.* from 职工表 t where 工资 = (select max(工资) from 职工表 where 部门 = t.部门)
职工号,姓名,工资,部门select a.* from 表 as a,(select 部门,max(工资) 工资 from 表 group by 部门) as b where a.部门=b.部门 and a.工资=b.工资
select 职工号,MAX(工资) FROM 职工表 GROUP BY 部门;
select * from 职工 where not exists (select a.职工号 from 职工 as a where a.工资> 职工.工资 and 职工.部门ID=a.部门ID)
---根据部分和工资联合a表查询结果 select a.职工号,a.姓名 from 职工 a inner join ( select 部门,max(工资) 工资 from 职工 group by 部门 ) b on (a.部门=b.部门 and a.工资=b.工资)
不要意思少发了一部分。下面是全部的 --找到每个部门最高的工资作为B表 select 部门,max(工资) 工资 from 职工 group by 部门---根据部分和工资联合a表查询结果 select a.职工号,a.姓名 from 职工 a inner join ( select 部门,max(工资) 工资 from 职工 group by 部门 ) b on (a.部门=b.部门 and a.工资=b.工资)其实还有很多方法
这段SQL文本身是无法正确执行的。“职工号”没有作为集计字段,执行会报错的。
你的课本上写的什么你看不明白啊?你把课本上的打出来找人给你解释吧。。我也是刚学的select 职工号 from 职工表 where 工资= (select max(工资) from 职工表 group by 部门)
呵呵,是我搞错了,多谢指点。更改如下: select 部门,职工号,工资 from 职工表 where 工资 in (select max(工资) from 职工表 group by 部门)
select t.* from 职工表 t where not exists(select 1 from 职工表 where 部门 = t.部门 and 工资 > t.工资) --这里使用not exists,意思是不存在这样的员工,部门与其它人的相同的,但是工资不比其它低 --不小于任何一个等于最大 <=any select t.* from 职工表 t where 工资 = (select max(工资) from 职工表 where 部门 = t.部门) --这里先用一个子查询,返回此部门的最大值,这里的 t.部门 就是传入的参数,再比较工资是否等于,如果等于的话,显示出来。
from 职工表 a
where not exists(selec 1 from 职工表 where 部门 = a.部门 and 工资>a.工资)
where a.部门=b.部门 and a.工资=b.工资
FROM 职工表
GROUP BY 部门;
from 职工
where not exists (select a.职工号 from 职工 as a where a.工资> 职工.工资 and 职工.部门ID=a.部门ID)
select a.职工号,a.姓名
from 职工 a
inner join
(
select 部门,max(工资) 工资
from 职工
group by 部门
) b
on (a.部门=b.部门 and a.工资=b.工资)
--找到每个部门最高的工资作为B表
select 部门,max(工资) 工资
from 职工
group by 部门---根据部分和工资联合a表查询结果
select a.职工号,a.姓名
from 职工 a
inner join
(
select 部门,max(工资) 工资
from 职工
group by 部门
) b
on (a.部门=b.部门 and a.工资=b.工资)其实还有很多方法
这段SQL文本身是无法正确执行的。“职工号”没有作为集计字段,执行会报错的。
where 工资=
(select max(工资) from 职工表 group by 部门)
呵呵,是我搞错了,多谢指点。更改如下:
select 部门,职工号,工资
from 职工表
where 工资 in (select max(工资) from 职工表 group by 部门)
--这里使用not exists,意思是不存在这样的员工,部门与其它人的相同的,但是工资不比其它低
--不小于任何一个等于最大 <=any
select t.* from 职工表 t where 工资 = (select max(工资) from 职工表 where 部门 = t.部门)
--这里先用一个子查询,返回此部门的最大值,这里的 t.部门 就是传入的参数,再比较工资是否等于,如果等于的话,显示出来。