1.--23.查詢每個部門工資最高的2-3名的員工
select m.ename,
m.salary,
m.deptno,
m.rn
from (select a.ename,
a.salary,
a.deptno,
row_number() over(partition by deptno order by salary desc) rn
from emp_zz a
group by a.ename, a.salary, a.deptno) m
where m.rn >=2 and m.rn <=3;
2.用 rank() over()分析函數
select m.ename,
m.salary,
m.deptno,
m.rank
from (select a.ename,
a.salary,
a.deptno,
rank() over(partition by deptno order by salary desc) rank
from emp_zz a
group by a.ename, a.salary, a.deptno) m
where m.rank >=2 and m.rank <=3;