LookingBeyond99
Programmer
Hi,
My problem is how do I create a rank column for a query. Meaning depending on a students score they will have a rank of 4 for example. Also if two students ahve the same score there rank should be the same and the next students rank would be 2 more. I tried using a global variable but dont know how to increment it properly. There must be an easier way of doin this then Im thinking of.
Select ID, Name, Score, @rank_count+=1
-> FROM Student
-> GROUP BY Score desc,Name limit 5;
ID Name Score Rank
213 Joe 75 1
432 Arthur 65 2
543 Jane 65 2
635 Larry 49 4
Thats how the results should print out. Everything works out except for the rank.
Thanks a lot!
My problem is how do I create a rank column for a query. Meaning depending on a students score they will have a rank of 4 for example. Also if two students ahve the same score there rank should be the same and the next students rank would be 2 more. I tried using a global variable but dont know how to increment it properly. There must be an easier way of doin this then Im thinking of.
Select ID, Name, Score, @rank_count+=1
-> FROM Student
-> GROUP BY Score desc,Name limit 5;
ID Name Score Rank
213 Joe 75 1
432 Arthur 65 2
543 Jane 65 2
635 Larry 49 4
Thats how the results should print out. Everything works out except for the rank.
Thanks a lot!