如何查 显示各部门工资前二位的员工 。各位大哥们帮帮忙!小弟我纠结啊!

解决方案 »

  1.   

    select rownum, ename from (select ename from scott.emp order by sal desc) where rownum between 1 and 2
    orselect ename from scott.emp where sal = (select max(sal) from scott.emp)
    union
    select ename from scott.emp where sal = (select max(sal) from scott.emp where sal != (select max(sal) from scott.emp))
      

  2.   


    select *
    from
    (select *
    from emp
    order by sal desc nulls last
    )a
    where rownum<=2;
      

  3.   

    select * 
    from emp a 
    where (
    select count(*) 
    from emp 
    where deptno = a.deptno 
    and sal > a.sal) <=1 
    and a.deptno is not null;