I've a game title application, I am monitoring the amount of games won per user, something similar to:

// table: users
id | username | num_games_won

Wouldso would I tell a person their overall ranking when it comes to num_games_won? For instance:

   id   | username | num_games_won
  723      john          203              
  724      mary          1924
  725      steve         391

The ratings could be: mary->0, steve->1, john->2. Given a username, wouldso would I've found their ranking number? (I am using mysql)


Try counting the amount of customers which have more games won the user you are looking at (by id or username)

WHERE num_games_won > (SELECT num_games_won FROM users WHERE id = 723)

Within this situation you are able to perform a simple ORDER BY. Regrettably, MySQL does not offer the nice analytical functions like RANK or ROWNUMBER that other databases support, because individuals could be other potential solutions once the answer is not as easy as ORDER BY.

(edit: you are able to kind of cheat and simulate [cde] in MySQL because of this answer on SO)

Within this situation, you'd do ROWNUMBER and also the first row might have probably the most, the 2nd might have second most, etc.