2 messages in com.mysql.lists.mysqlNewbie: Ranking-Statement
FromSent OnAttachments
Horst Jäger02 Aug 2004 04:22 
Brent Baisley02 Aug 2004 07:01 
Subject:Newbie: Ranking-Statement
From:Horst Jäger (h.ja@medienkonzepte.de)
Date:08/02/2004 04:22:53 AM
List:com.mysql.lists.mysql

Hi,

suppose I've got a table "RichMan" with columns

ID, Name, Bucks

1, 'John', 300 2, 'Joe', 700 3, 'Al', 400 4, 'Fred', 250 5, 'Jim', 480

and I sort them with respect to "Bucks". Then John would be on the first place because he ist the richest, followed by 'Jim', etc.

Now I'm looking for an SQL-Statement "select blablabla from RichMan blablabla ID"

which returns me the rank of the ID if sorted by Bucks.

So: "select blablabla from RichMan blablabla 1" would return 4 because John with the ID 1 is the 4th-richest. "select blablabla from RichMan blablabla 3" would return 2 because Al with the ID 3 is the 3rd-richest.

And so on.

It would also be interesting to do it the other way round: give the rank and get the ID

Thanks in advance

Horst