Distinct
est plus lent que Group By
. Vous pouvez continuer comme ça sans utiliser Group By
et Distinct
ensemble et cela pourrait être ce que vous voulez réaliser.
SELECT regd, Roll_no, Name_of_Student, Name_of_exam,
TOTALSCORE, Rank
FROM
(
SELECT t.*, IF(@p = TOTALSCORE, @n, @n := @n + 1) AS Rank, @p := TOTALSCORE
FROM
(
SELECT regd, Roll_no, Name_of_Student, Name_of_exam,
SUM(Mark_score) TOTALSCORE
FROM cixexam, (SELECT @n := 0, @p := 0) n
WHERE (Name_of_exam='First Terminal Exam' OR Name_of_exam='First Term Test')
GROUP BY regd
ORDER BY TOTALSCORE DESC
) t
) r