title: MySQL If Statement and Increment
body: <p>I am having issues with a MySQL If statement that creates a group rank. here is the MySQL Statement:</p>
  
  <pre><code>SELECT EnCode, EnName, QuScore, 
  @scorerank := IF(@currathlete = EnCode, @scorerank + 1, 1),
  @currathlete := EnCode
  FROM ranking ORDER BY EnCode, QuScore DESC
  </code></pre>
  
  <p>It currently gives the following output</p>
  
  <pre><code>'1004277','Ashe','1628','1','1004277'
  '1004277','Ashe','1309','1','1004277'
  '1004277','Ashe','1263','1','1004277'
  '1004277','Ashe','648','1','1004277'
  '1004277','Ashe','645','1','1004277'
  '1004277','Ashe','1628','1','1004277'
  '1015934', 'Sabina', '544', '1', '1015934'
  '1015934', 'Sabina', '455', '1', '1015934'
  '1015934', 'Sabina', '276', '1', '1015934'
  '1015934', 'Sabina', '216', '1', '1015934'
  </code></pre>
  
  <p>What it should be doing is incrementing each of the '1' numbers by one for each row that has the same code, and then starting from 1 again when it sees a different code number (1004277, then 1015934 in this case)</p>
  
  <p>Any help is appreciated as i have followed a number of examples online using the above method but seem to hit the same issue a this point.</p>