MySQL rank calculation with all entries at 0 -
i have following sql script ranks set of users in leaderboard table.
update leaderboard join (select f.winnings , if (@lastpoint <> f.winnings, @currank := @currank +1, @currank) rank, @lastpoint := f.winnings leaderboard f join (select @currank := 0, @lastpoint := 0) r f.competition =5 order f.winnings desc ) ranks on (ranks.winnings = leaderboard.winnings) set leaderboard.rank = ranks.rank leaderboard.id =89;
however when users have rank of 0 not rank them 1 (i.e equal) behaviou occurs 0.
winnings rank 0 0 0 0 0 0
would know how this..?
winnings rank 0 1 0 1 0 1
sql fiddle http://sqlfiddle.com/#!2/53c3a/1
the <>
test fails
update leaderboard join (select f.winnings , if (@lastpoint <> f.winnings, @currank := @currank +1, @currank) rank, @lastpoint := f.winnings leaderboard f join (select @currank :=0, @lastpoint :=-1) r order f.winnings desc ) ranks on (ranks.winnings = leaderboard.winnings) set leaderboard.rank = ranks.rank;
Comments
Post a Comment