select staff_number
from (select staff_number
,rank() over(partition by department order by salary desc) rn --更具部门分组排序。
from table_name) tn
where rn = 1
也可以取每个部门最高工资前N位
select empno from emp where sal in (select max(sal) from emp group by deptno)
这是ORACLE中自带的几张表,emp表代表员工表,换成你自己的表即可
select 员工编号
from tab t
where not exists (select 1 from tab where 部门 = t.部门 and 工资 > t.工资)
select emp.empno ,emp.sal ,emp.deptno,a.msal from emp,(select max(sal) msal ,deptno from emp group by deptno) a where emp.sal=a.msal and a.deptno=emp.deptno;