When I needed to do something like this, I created a view that looked like this:
CREATE VIEW rankings_view AS SELECT id , point , (select count(1) from points b where b.point > a.point) +1 as rank FROM points as a;
This suggests that the source table was called dots, obviously. You can then get the rank of any identifier or identifier corresponding to any rank by querying the submission.
EDIT
If you want to count the number of different point values above each point value instead of the number of records with points above the current point value, you can do something like:
CREATE VIEW rankings_view2 AS SELECT id , point , (SELECT COUNT(1) +1 AS rank FROM ( SELECT DISTINCT point FROM points b WHERE b.point >a.point )) FROM points AS a;
Note
Some of the solutions presented certainly work better than this. They are specific to mysql, so I cannot use them for my actions. My application has at most 128 objects for ranking, so this works pretty well for me. However, if you can have many lines, you can look at using one of the other solutions presented here, or limit the scope of the rating.
lo5an
source share