select deptid, empname, salary from emp e1 where ( select count(1) from emp e2 where e2.deptid=e1.deptid and e2.salary>=e1.salary ) <=3 /*这里的数值表示你想取前几名*/ order by deptid, salary desc;