SuperFrog
SuperFrog

Reputation: 7674

MySql - get user rank by result

Given this table structure:

ID | USER | SCORE |SCORE_DATE

I want to create a query which result is the rank of a score - my routine will get a parameter of score and will return the rank.

Given this data:

1 | user1 | 1300 | 1/2/2014

2 | user2 | 3300 | 1/2/2014

3 | user3 | 4300 | 1/2/2014

4 | user4 | 650 | 1/2/2014

5 | user5 | 1700 | 1/2/2014

If the paramter passed is 4000, I want the result to be 2, if the result is 2000 the result should be 3, if the paramter is 500 the result should be 6 etc.

Upvotes: 0

Views: 70

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269563

You can use count and where:

select count(*)+1
from table t
where score > SCORE_PARAMETER;

Upvotes: 1

Related Questions