我有一个大约10行的表格
empno,ename,dept,sal,deptno
现在我希望结果作为最大sal的每个部门的ename。
EX:
12,ravi,manager,20000,10
43,hari,engineer,10000,20
32,sam,clerk,5000,30
答案 0 :(得分:0)
获得每个部门的最高工资,然后获得每个最高工资的ename。
select ename,dept,sal
from emp
where sal in (select max(sal) as sal from emp group by dept)
使用row_number()
和partition
select * from
(
select ename,dept,sal, row_number() over (partition by dept order by sal desc) as row_no
from emp
) res
where res.row_no = 1