SELECT UserId, @i:=@i+1,grade FROM userinfo a,(SELECT @rownum:=0) b ORDER BY grade DESC; 转载于:https://www.cnblogs.com/andy_tigger/archive/2011/05/07/2039926.html