我要查询每个部门工资前3名的
select name,bumen,max(salary) from user group by bumen;
我只会选出最大的,至于前三个,感觉不好弄
select *
from (select name,
bumen,
salary,
row_number() over(partition by id order by salary desc) rn
from user)
where rn <= 3
这个应该可以!
select * from table where salary in
(select top 3 salary from table group by salary order by salary desc);
或者这个也行!
非得一步到位么?按降序查出来一个结果集,然后写个遍历取前3个就行?