Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a rank column for query

Status
Not open for further replies.

LookingBeyond99

Programmer
Jul 2, 2001
18
0
0
US
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!
 
I would let the application code handle it...easier to manage


Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top