为什么仓位不醒SQL

时间:2019-04-09 12:41:42

标签: php sql

我下面的代码可以正常工作,但不能按整体标记的降序顺序打印结果。而是按学生ID的顺序排列它。

我有安排学生位置的代码。它适用于一年的值,但是当要考虑的时间超过一年时,它不会按降序打印结果...

以下是将标记表连接到学生表的代码:

SELECT * FROM (
SELECT  student_id, term, academic_year, classform_name, @prev:=@cur, @cur:=overall, @curRank := IF(@prev= @cur, @curRank, @curRank + @i ) AS classPosition, IF(@prev<> overall, @i:=1, @i:=@i+1) AS counter
FROM (SELECT m.*, SUM(total_marks) AS overall
    FROM marks m
    WHERE classform_name = ? AND term = ? AND academic_year = ? 
    GROUP BY m.student_id
    ORDER BY overall DESC
) AS n 
CROSS JOIN (SELECT  @i:=0, @curRank := 0, @prev:=NULL, @cur:=NULL ) AS q 
) AS completeRankings 
  JOIN studentstable ON completeRankings.student_id=studentstable.student_id ;

1 个答案:

答案 0 :(得分:0)

我已经使用JavaScript dataTables解决了它。我将记录从最高分到最低分重新排序