Distinct
er langsommere end Group By
. Du kan gå sådan her uden at bruge Group By
og Distinct
sammen, og det kunne være det, du ønsker at opnå.
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