-2

我试图首先让用户获得每个级别的最高分,然后将每个分数相加以找到用户的总体高分。

+-----------+----------+----------+--------------------+
| id        | name     | score    | level_id           |
+-----------+----------+----------+--------------------+
|         1 | Jane Doe | 100      |                  1 | 
|         2 | Jane Doe | 50       |                  2 | 
|         1 | John Doe | 100      |                  1 |
|         2 | John Doe | 50       |                  2 |
+-----------+----------+----------+--------------------+

我已经设法找到用户在所有级别的最高分,但是我怎样才能为每个级别做到这一点

select user_id, id, max(correct_answers)
from score
group by user_id
4

3 回答 3

1

尝试这个

   select user_id, max(correct_answers) maxs ,level_id
   from score
   group  by level_id,user_id

演示

于 2013-07-30T09:20:25.817 回答
0

在 group by 中添加 level_id

select user_id, id, max(correct_answers)
from score group by user_id,level_id
于 2013-07-30T09:14:46.090 回答
0

尝试这个:

通过 level_id,id 从分数组中选择名称、id、max(score)

于 2013-07-30T09:22:19.863 回答