Distinct
е по-бавно от Group By
. Можете да отидете така, без да използвате Group By
и Distinct
заедно и това може да е това, което искате да постигнете.
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