赞
踩
注:MySQL版本8.0以上才支持以下函数
ROW_NUMBER()函数在排名时序号 连续且不重复,即使表中的两个一样的值时也是这样
select *,row_number() OVER(order by number ) as row_num
from num
ORDER BY id
Rank() 函数会把要求排序的值相同的归为一组且每组序号一样,排序不会连续执行,即排序时 重复且不连续
select *,rank() OVER(order by number ) as row_num
from num
Dense_rank() 函数排序是连续的,也会把相同的值分为一组且每组排序号一样,即排序时 重复且连续
select *,dense_rank() OVER(order by number ) as row_num
from num
Ntile(group_num) 将所有记录分成group_num个组,每组序号一样
select *,ntile(2) OVER(order by number ) as row_num
from num
参考链接:https://leetcode.cn/problems/rank-scores/solution/si-da-pai-ming-han-shu-he-guan-jian-zi-b-qvaz/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。