2

有史以来第一个 q Whohoo!

我有一个带有数据的 mySQL 表

**username**   **score**   
Count Joe         278     
Count Joe         255
Count Joe         298
Count Joe         289

我在显示以下结果集时遇到问题:

**RANK** **USERNAME** **SCORE**
1 Count Joe 255
2 Count Joe 278
3 Count Joe 289
4 Count Joe 298

目前它正在返回

**RANK** **USERNAME** **SCORE**
    1 Count Joe 255
    22 Count Joe 278
    32 Count Joe 289
    18 Count Joe 298

使用

SET @ROW=0; SELECT @ROW:=@ROW + 1 AS rank, username, total FROM game_scores GROUP BY username ORDER BY total ASC LIMIT 10

上面的查询似乎返回了查询表中的索引位置或用户。

4

1 回答 1

0
SELECT @curRow := @curRow + 1 AS rank, s1.*
FROM
(
    SELECT   username, score
    FROM     scores    
    GROUP BY username ORDER BY score ASC LIMIT 10
) AS s1
JOIN (SELECT @curRow := 0) r
于 2013-10-09T15:32:57.587 回答