3

Possible Duplicate:
How do I Handle Ties When Ranking Results in MySQL?

I'd like to order the table Status by Activepoints and insert the rank into a column rank. It comes:

RANK   USERNAME   ACTIVEPOINTS

 1     monkey100     92
 2     fresnoJump    54
 3     otherUser9    54

but it should display NOT unique ranks like

RANK   USERNAME   ACTIVEPOINTS

 1     monkey100     92
 2     fresnoJump    54
 2     otherUser9    54
Community
  • 1
  • 1
Smoothie
  • 261
  • 4
  • 11

1 Answers1

1

I think this is solved with 2 UDF variables http://dev.mysql.com/doc/refman/5.0/en/user-variables.html.

SET @rank = 0, @previous_active_points = 0;
SELECT IF(@previous_active_points<>Activepoints,@rank:=@rank+1,@rank) AS rank,
@previous_active_points:=Activepoints,username,Activepoints 
FROM `status` ORDER BY Activepoints

Hope it helps!

georgepsarakis
  • 1,927
  • 3
  • 20
  • 24