欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

查询每个部门的工资最高的同事的姓名,及工资是多少

程序员文章站 2022-03-18 22:23:37
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 ) ... ......
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