tags:

views:

20

answers:

2

I have a table called 'points' that has a field 'total' which contains the total points for a record. Now I would like to calculate the rank of a specific record.

So like: SELECT (...) as rank FROM points WHERE id=63

Is this possible in SQL?

+1  A: 

Count the rows where points are higher + 1 and total rows.

MatTheCat
Stupid I did not came up with this myself. Thank you MatTheCat! :)
Jens
You're welcome ^^
MatTheCat
A: 
SET @rownum := 0;
SELECT rank, total FROM (
                    SELECT @rownum := @rownum + 1 AS rank, total, id
                    FROM points  ORDER BY total DESC
                    ) as result WHERE id=63
pinichi