I get stuck in creating unique numbers for unique values. I have 25 rows in MySQL table I want to assign rank on it. Suppose 10 users got same values: I want to assign them same number and the rest of them would be unique. I have following MySQL query:
(SELECT std_login_id AS ID, STD_NAME, TOTAL_MARKS, (@rnk := @rnk + 1) AS RANK FROM
(SELECT ob.std_login_id, SUM(ob.marks_obtain) AS TOTAL_MARKS, std.student_name AS STD_NAME
FROM exam_marks_obt ob
JOIN ac_std_preadmission STD ON ob.std_login_id = std.std_login_id
JOIN adm_class AS cl ON cl.class_id = std.class_id
JOIN adm_section se ON se.section_id=std.section_id
WHERE cl.class_id = 1 AND se.section_id = 1
GROUP BY ob.std_login_id
ORDER BY ABS(SUM(ob.marks_obtain)) DESC)
ob CROSS JOIN (SELECT @rnk := 0) AS flyRank )
;
Following are the result:
ID | STD_NAME | TOTAL_MARKS | RANK
1 | name1 | 250 | 1
2 | name2 | 250 | 2
3 | name3 | 200 | 3
4 | name4 | 200 | 4
5 | name5 | 150 | 5
6 | name6 | 150 | 6
I want to generate Rank Like this for 250=>1, and 200=>2, and 150=>3. Please tell me what can I do in my code to generate this rank?