MySQL-分析函数-rank-排名/排序
作者:互联网
有三个函数:
rank()
dense_rank()
row_number()
拿一个表Employee作为例子:
Name Salary --------------- abc 100000 bcd 1000000 efg 40000 ghi 500000
jkl 500000
查询脚本:
```sql
select name,
salary,
rank() over(order by salary) as rnk,
dense_rank() over(order by salary) as dense_rnk,
row_number() over(order by salary) as row_number
from Employee;
查询结果:
name salary rnk dense_rnk row_number
efg 40000 1 1 1
abc 100000 2 2 2
ghi 500000 3 3 3
jkl 500000 3 3 4
bcd 1000000 5 4 5
通过dense_rank()可以查询根据salary排序获得任意一名
参考网站:https://www.geeksforgeeks.org/sql-query-to-find-second-largest-salary/
标签:salary,rnk,dense,number,rank,MySQL,500000,排序 来源: https://www.cnblogs.com/za-ill-ds/p/13098194.html