1、找出每个部门工资前三高的员工。
该题用到row_number() over()分析函数
select department,employee,salary
from (select d.name as department,
e.name as employee,
e.salary as salary,
row_number() over(partition by d.name order by e.salary desc) rn
from employee e
inner join department d
on e.departmentid = d.id)
where rn < 4;
row_number() over(partition by d.name order by e.salary desc)
该句为按d.name分组,在分好组的情况下再按e.salary 降序排序