我想按Status
订购表格Activepoints
,然后将排名插入到列rank
中。
它来了:
RANK USERNAME ACTIVEPOINTS
1 monkey100 92
2 fresnoJump 54
3 otherUser9 54
但它应该显示非唯一的排名,如
RANK USERNAME ACTIVEPOINTS
1 monkey100 92
2 fresnoJump 54
2 otherUser9 54
答案 0 :(得分:1)
我认为这是通过2个UDF变量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
希望它有所帮助!