1. 程式人生 > >查詢每個部門的工資最高的同事的姓名,及工資是多少

查詢每個部門的工資最高的同事的姓名,及工資是多少

spa order color inner group style 查詢 class tno

1 select t1.empno, t1.ename, t1.deptno, t1.sal
2 from emp t1
3 inner join (
4     select t2.deptno, max(sal) max_sal
5     from emp t2
6     group by t2.deptno ) t3
8     on ( t1.deptno = t3.deptno and t1.sal = t3.max_sal )
9     order by t1.sal

查詢每個部門的工資最高的同事的姓名,及工資是多少