现有需求要求查询emp表每个部门工资最高的员工名称、薪水:
select ename,deptno,sal from emp where (deptno,sal) in (select deptno,max(sal) from emp group by deptno);
select ename,e.deptno,e.sal from emp,(select deptno,max(sal) sal from emp group by deptno) e
where e.deptno = emp.deptno and e.sal = emp.sal;
select ename,deptno,sal from (select ename,sal,deptno,rank() over(partition by deptno order by sal desc) rk
from emp) where rk=1;