1

不知道是什么原因造成的,但我试图获得该级别所有答案中得分总和最高的级别。

Cursor c = myDataBase
                .rawQuery(
                        "select level "
                                + "from answers where player ='"
                                + player
                                + "' group by level order by sum (score) desc",
                        null);

一定级别的所有答案都有一个分值。它不断返回第 10 级(共 10 级),而实际上另一个级别的得分最高......如果我应用 asc 顺序,它就可以正常工作:s

4

3 回答 3

2

如果您只想获得最高分的级别,请尝试使用having如下:

            "select level "
            + "from answers where player ='"
            + player
            + "' group by level "
            + " having sum (score) = max(sum (score))";

编辑:

            "select level from (select level, max(levelscore) as maxscore from "+
                               +" (select level, sum (score) as levelscore, "
                               + " from answers where player ='"
                               + player
                               + "' group by level )"
            + " ) where levelscore = maxscore";

或者

           "select level from "+
                   +" (select level, sum (score) as levelscore, "
                   + " from answers where player ='"
                   + player
                   + "' group by level )"
                   + "order by levelscore desc LIMIT 1";
于 2012-12-03T15:21:36.693 回答
1
SELECT level, SUM( score ) AS scoresum
FROM answers
WHERE player = ?
GROUP BY level
ORDERBY scoresum DESC
LIMIT 0, 1
于 2012-12-03T16:26:09.823 回答
0

为什么不这样声明(更容易)

SELECT TOP 1 level 
FROM answers 
WHERE player = {player} 
ORDER BY score DESC

请注意,如果您在“保存”播放器的第一个结果之前执行此查询,您将不会得到任何结果...

哔叽

于 2012-12-03T15:24:48.400 回答