4

我有一个标记表,例如:

ID STUDENT_ID Branch_id Class_id Exam_id Subject_id Numbers Date
1 653 5 1 1 8 60 2012-01-01
2 653 5 1 1 9 40 2012-01-01
3 653 5 1 1 10 80 2012-01-01
4 653 5 1 1 11 50 2012-01-01
5 653 5 1 1 12 65 2012-01-01
6 653 5 1 1 13 33 2012-01-01
7 653 5 1 1 15 86 2012-01-01
8 222 5 1 1 8 100 2012-01-01
9 222 5 1 1 9 80 2012-01-01
10 222 5 1 1 10 92 2012-01-01
11 222 5 1 1 11 50 2012-01-01
12 222 5 1 1 12 65 2012-01-01
13 222 5 1 1 13 33 2012-01-01
7 222 5 1 1 15 86 2012-01-01

如果一个或多个学生的等级相同,我需要知道学生的等级。并使用分支和类 ID 进行过滤。

谁能帮我?

4

2 回答 2

2

试试这个:

SELECT STUDENT_ID, Numbers, IF(@marks=(@marks:=Numbers), @auto, @auto:=@auto+1) rank 
FROM (SELECT STUDENT_ID, Branch_id, Class_id, SUM(Numbers) Numbers
      FROM quiz_user 
      GROUP BY STUDENT_ID 
      ORDER BY Numbers DESC, STUDENT_ID 
     ) AS A, (SELECT @auto:=0, @marks:=0) AS B
WHERE Branch_id = 5 AND Class_id = 1; 
于 2013-01-16T06:48:13.087 回答
0
select sum(Numbers),STUDENT_ID,Branch_id,  Class_id
from marksheet 
where Branch_id='value' and Class_id='valueClass'
group by STUDENT_ID,Branch_id,  Class_id
order by sum(Numbers) desc

小提琴演示在这里

于 2013-01-14T07:12:45.907 回答