SQL中查询每个部门工资最低的两个员工的姓名,工资

emp ,dept 表,姓名ename,工资sal,求助各位大神解答呀~~谢谢!

select top 2 工资 from 表 where 部门 = (select top 2 部门 from 表
order by 工资 ) order by 工资 同

select top 2 工资 from 表 where 部门 = (select top 2 部门 from 表
order by 工资 ) order by 工资

select top 2 工资 from 表 where 部门 = (select top 2 部门 from 表
order by 工资 ) order by 工资 同

可以使用oracle的聚合函数!具体业务逻辑你怎么用,百度一下 oracle聚合函数,就知道怎么用啦

group by会不会?不会就去看看书

select top 2 工资 from 表 where 部门 = (select top 2 部门 from 表
order by 工资 ) order by 工资

select MIN(emp.sal),dept.id,emp.name from emp left join dept on emp.deptId = dept.id
group by dept.id,emp.name 这个方法是求各部门工资最低的员工姓名

先按每个部门内的工资高低排序编号,再取前2位

 select * from (
select ROW_NUMBER() OVER(PARTITION BY 部门id ORDER BY 工资数) rn,人员名字 from 表 
) where rn<=2