I have a table users:
id | rating
1 4
2 -1
3 12
4 0
5 2
6 0
How I can select user’s place ordering by rating where id = N and that users with similar rating have the same place in the top?
UPD: I want to output:
If userid = 1, his rank is 2, if userid = 2, his rank is 5, if userid = 3, rank is 1, …
But if userid = 4 or 6 their rank are 4 because rates are similar.
I think you want to find the rating for asll user_id’s`:
Example @ sqlfiddle
If you don’t want to change the order of records in output then try this: