SET @rownum := 0;
SELECT rank, student_marks FROM (
SELECT @rownum := @rownum + 1 AS rank, student_marks, student_Id
FROM student ORDER BY student_marks DESC
) as result WHERE student_Id=3;
SELECT
s1.student_name, COUNT(DISTINCT s2.student_marks) AS rank
FROM
student s1 JOIN student s2 ON (s1.student_marks <= s2.student_marks)
GROUP BY s1.student_Id;
SELECT
student_Id, student_name, student_marks,
@prev := @curr,
@curr := student_marks,
@rank := IF(@prev = @curr, @rank, @rank+1) AS rank
FROM
student,
(SELECT @curr := null, @prev := null, @rank := 0) sel1
ORDER BY student_marks DESC;
SELECT rank, student_marks FROM (
SELECT @rownum := @rownum + 1 AS rank, student_marks, student_Id
FROM student ORDER BY student_marks DESC
) as result WHERE student_Id=3;
SELECT
s1.student_name, COUNT(DISTINCT s2.student_marks) AS rank
FROM
student s1 JOIN student s2 ON (s1.student_marks <= s2.student_marks)
GROUP BY s1.student_Id;
SELECT
student_Id, student_name, student_marks,
@prev := @curr,
@curr := student_marks,
@rank := IF(@prev = @curr, @rank, @rank+1) AS rank
FROM
student,
(SELECT @curr := null, @prev := null, @rank := 0) sel1
ORDER BY student_marks DESC;