我想根据他获得的分数计算每个学生的排名。但是,如果标记在 -ve 值中,则查询不会显示适当的答案。
SELECT a1.ResultByTestId, a1.ObtainedMarks, COUNT(a2.ObtainedMarks) Rank
FROM ResultByTest a1, ResultByTest a2
WHERE a1.ObtainedMarks < a2.ObtainedMarks
or
(a1.ObtainedMarks=a2.ObtainedMarks and a1.StudentId = a2.StudentId)
GROUP BY a1.ObtainedMarks, a1.ResultByTestId
ORDER BY a1.ObtainedMarks DESC, Rank DESC
答案表是:-
resutlByTestId ObtainedMarks Rank
11 36 1
10 22 2
3 9 3
9 7 4
6 5 5
8 3 6
7 2 7
4 0 8
5 0 8
1 0 8
2 0 8
13 -5 12
有人帮我吗?