mysql相同数值排序

select
tmp.id,tmp.name,tmp.score,
– 顺序一直在变大
@j:=@j+1 as j,
– 只有在前后二次排序值不同时才会使用顺序号
@k:=(case when @pre_score=tmp.score then @k else @j end) as rank,
@pre_score:=tmp.score as pre_score
from
(
– 成绩排序
select * from score order by score desc
) tmp,
– @k 表示最终的排名(相同值时序号相同)
– @j 表示顺序排名
– @pre_score上一次排序值
(select @k :=0,@j:=0, @pre_score:=0) sdcore

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!