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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -