Well, giving the rank and getting the ID is simple:
SELECT * FROM RichMan ORDER BY Bucks DESC LIMIT 4,1

That will return 1 record starting at the 4th record.

The first one is a bit tougher. Thinking on it.

On Aug 2, 2004, at 7:23 AM, Horst Jäger wrote:

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


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to