我有下面的SQL脚本,它在排行榜表中排列一组用户。

UPDATE leaderboard
JOIN   (SELECT f.winnings ,
IF     (@lastPoint <> f.winnings,
        @curRank := @curRank +1,
        @curRank) AS rank,
        @lastPoint := f.winnings
FROM   leaderboard f
JOIN   (SELECT @curRank := 0, @lastPoint := 0) r
WHERE f.competition =5
ORDER BY f.winnings DESC
) ranks ON (ranks.winnings = leaderboard.winnings)
SET leaderboard.rank = ranks.rank WHERE leaderboard.id =89;

但是,当所有用户的排名都为0时,它不会将他们排名为1(即相等),这种行为仅发生在0上。
winnings  rank
0          0
0          0
0          0

有人知道怎么做吗。。?
winnings  rank
0          1
0          1
0          1

SQL小提琴http://sqlfiddle.com/#!2/53c3a/1

最佳答案

<>测试失败

UPDATE leaderboard
JOIN   (SELECT f.winnings ,
IF     (@lastPoint <> f.winnings,
        @curRank := @curRank +1,
        @curRank) AS rank,
        @lastPoint := f.winnings
FROM   leaderboard f
JOIN   (SELECT @curRank :=0, @lastPoint :=-1) r
ORDER BY f.winnings DESC
) ranks ON (ranks.winnings = leaderboard.winnings)
SET leaderboard.rank = ranks.rank;

10-07 16:52