语法:ROW_NUMBER() OVER(PARTITION BY COLUMN<针对排名的字段> ORDER BY COLUMN<需要排名的字段> (desc<倒序>))
SELECT *, Row_Number() OVER (partition by deptid ORDER BY salary desc) rank FROM employee where rank <= 20;
可查处以deptid字段分组的 salary值最大的前20名
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/196393.html