MySQL触发学生排名

时间:2015-08-15 07:50:23

标签: mysql triggers

  

如何将此转换为触发器(学生排名)

SET @prev_value = NULL;
SET @rank_count = 0;
SET @rank_increasing = 0;
SELECT @rank_increasing := @rank_increasing + 1 AS NO
     , CASE
       WHEN @prev_value = a.total_score
          THEN @rank_count
       WHEN @prev_value := a.total_score
          THEN @rank_count := @rank_increasing 
        END AS RANK
     , a.*
  FROM ( SELECT STUDENT_ID,TERM,YEAR,
 SUM(TEST)  AS total_score

           FROM studentmark
          GROUP BY STUDENT_ID
          ORDER BY total_score DESC
       ) a 
  

任何人都可以帮我做这个

0 个答案:

没有答案