我有选择查询,选择学生分数,并从最高到最低排名,这个mysql查询第一次工作,但是当我第二次在phpmyadmin上运行时,它返回NULL,它应该显示在学生的等级,下面是mysql查询;
SELECT @rownum := @rownum + 1 AS rank
, student_name
, avga
FROM `averaga`
WHERE class="Form 1A"
ORDER
BY avga DESC
答案 0 :(得分:2)
您需要初始化变量。我通常在查询中执行此操作:
SELECT (@rownum := @rownum + 1) AS rank, student_name, avga
FROM `averaga` a CROSS JOIN
(SELECT @rownum := 0) params
WHERE class = 'Form 1A'
ORDER BY avga DESC;