请求帮忙,关于oracle数据库的问题,谢谢!

2025-05-05 13:38:46
推荐回答(2个)
回答1:

--题目:在工资最高的前3名职工所在部门中查询工资最低的职工
select * from emp where (deptno,sal) in(
select deptno,min(sal) from emp where deptno in(
(select distinct deptno
from (select * from emp where job <> 'PRESIDENT' order by sal desc) --按照工资排序,当然你把老板要排除在外的
where rownum <= 3) ) --排序后取前三的部门名称
group by deptno)

回答2:

select deptno,ename,sal from ( select deptno,ename,sal from emp 3 where rownum<=3 order by sal desc) order by sal limit 1