嘿我有这个数据的阶梯排名:
忽略胜利,失败,等等。
问题是,在团队表上我有一个排名列,我在图像表上使用的排名只是一个从0开始的i变量,在完成while循环时增加1。 如何使用Points排序的实际排名更新排名列?
答案 0 :(得分:0)
您可以使用update
/ join
:
update rankings r join
(select r.id, @rn := @rn + 1 as ranking
from rankings r cross join
(select @rn := 0) vars
order by points desc
) rp
on r.id = rp.id
set r.ranking = rp.ranking;
子查询使用变量来计算排名。