title: Mysql sorting by
body: <p>I'm working on how to implement a leaderboard.  What I'd like to do is be able to sort the table by several different filters(score,number of submissions, average).  The table might look like this.</p>
  
  <pre><code>+--------+-----------------------+------+-----+---------+-------+
  | Field  | Type                  | Null | Key | Default | Extra |
  +--------+-----------------------+------+-----+---------+-------+
  | userID | mediumint(8) unsigned | NO   | PRI | 0       |       |
  | score  | int                   | YES  | MUL | NULL    |       |
  | numSub | int                   | YES  | MUL | NULL    |       | 
  +--------+-----------------------+------+-----+---------+-------+
  </code></pre>
  
  <p>And a sample set of data like so:</p>
  
  <pre><code>+--------+----------+--------+
  | userID | score    | numSub |
  +--------+----------+--------+
  | 505610 | 1245     | 2      |    
  | 544222 | 1458     | 2      |
  | 547278 | 245      | 1      |
  | 659241 | 12487    | 8      |
  | 681087 | 5487     | 3      |
  +--------+----------+--------+
  </code></pre>
  
  <p>My queries will be coming from PHP.  </p>
  
  <pre><code>// get the top 100 scores
  $q = "select userID, score from table order by score desc limit 0, 100";
  </code></pre>
  
  <p>this will return a set of userID/score sorted highest score first
  I also have a query to sort by numSub (number of submissions)  </p>
  
  <p>What I would like is to sort the table by the avg score that being score/numSub;  The table could be large so efficiency is important to me.</p>
  
  <p>Thanks in advance!</p>