How to add ranks to a point system

I have a system where you can earn points by guessing the good results. When you have the most points, you have to be the number 1. The question is how I can make ranks, so that the guy with the most points will be the number 1, the next guy will be number 2, etc.

Example:

    ID    Points  Rank
  -------------------------
    1   | 1000  | 1
    2   |  900  | 2
    3   |  500  | 5
    4   |  700  | 4
    5   |  800  | 3

Thanks!

Answers


Let's imagine that you have a database with two tables: the first one lists users and the seccond one lists points earned by questions (the questions come from a third table that's not important although I'll show it below).

User
=====
Id
Name
(...)

Question
=====
Id
(...)

Answer
=====
UserId
QuestionId
PointsTaken

To do a rank from that, you can do a simple SQL statement:

SELECT usr.Id, usr.Name, SUM(ans.PointsTaken)
  FROM User usr
  JOIN Answer ans ON ans.UserId = usr.Id
 GROUP BY usr.Id, usr.Name
 ORDER BY SUM(ans.PointsTaken) DESC

This way, your rank is done. The result will be the person Id, the person Name, and the total of points taken, ordered from max to min. Next to this, you just need to show the information.


Need Your Help

Store an image in an array using Python

python arrays numpy

I need to read images (500x300x3) and store them in arrays:

How to perform a faceted search?

java lucene information-retrieval faceted-search

I'd like to know how to perform a faceted search using lucene.facet. I'll explain exactly what I want to do: I've got a taxonomy of htmlfiles (similar to ODP) and I want that, given a query, display