title: MySQL - Get count() for each row in a group with different condition
body: <p>I have a high scores table <code>scores: (id int, deviceid int, value int, board int)</code>.
  I'd like to display a position for a specific player. At the moment I'm doing this (in PHP):</p>
  
  <p>I select all boards where the player has a score and the score itself:</p>
  
  <pre><code>select board, min(value) as value
  from scores
  where deviceid = 1234
  group by board
  </code></pre>
  
  <p>Then for each row ($board,$value) I select:</p>
  
  <pre><code>select count(id) from scores
  where board = $board and value &lt; $value
  </code></pre>
  
  <p>by selecting number of rows for specific board with score less than specified value, I get the player's position (first player would get position 0, so it will be increased by 1 when displayed)</p>
  
  <p>I know this is horribly unefficient, so I'm looking for a <strong>way to do it faster</strong>. It could possibly be done in a stored procedure with a cursor, but for 100 boards, I will need to do at most 1+100 selects. </p>
  
  <p>I a nutshell, I would like to do something like this, in pseudo-sql:</p>
  
  <pre><code>select board, min(value) as val,
         count(id) from _this_group_ where value &lt; val
  from scores
  where deviceid = 1234
  group by board
  </code></pre>