ranking or incrementing results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

ranking or incrementing results

Post by magicrobotmonkey »

What I am trying to do here is to rank the results I am getting based on one column, but order them based on another column.

For instance, say I've got a table locations. I want to query it such that I get a rank based on the score, but I want it ordered by the location name. Is this even possible?

I am using MySQL
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't understand...maybe a pseudo-query would help. :?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

ok lets say I have table locatoins

Code: Select all

LOCATIONS
LocID
LocName
LocScore
Now what I want to do is get a result ordered by LocName. I also want to know the score, but not the actual score, rather, the rank of the score, as if i was ordering by LocScore descending, which number it would be. So if there were three shops scoring 100, 100, and 95, their ranks would be 1, 1, an 2 respectivly. In essence I am trying to order by two different columns. I am afraid this may be unpossible, and I am trying to work out a way to do it by some sorting of the resulting arrays, but the size of them frightens me.
Post Reply