select Score, case when @prevScore = Score then @rank when (@prevScore := Score) is not null then @rank := @rank+1 end as Rank from Scores, (select @rank := 0, @prevScore := NULL) a order by Score desc;
share an useful link:
Return string not int :(
I had a very very similar idea as yours, only differs in the line
(@prevScore := Score) is not null
Could someone kindly explain to me what's happening in this line?
I know that if
is not null is not here, we would have trouble finding the correct answer then the Score equal to zero and there's only one row. But why adding
is not null solve this problem?