title: Possible to add auto incrementing variable to row results of GROUP BY in mysql?
body: <p>Basically, I'm using this query to group a bunch of users based on the sum of numbers associated with them.  I need to some how assign an index to each result.  I am blanking on how to do this.  I'm thinking I need to alias something with AS but not sure quite how.  Any ideas?</p>
  
  <p>This is the current query where I switch out the page and per dynamically:</p>
  
  <pre><code>SELECT COUNT(*) as count, user_id, SUM(earnings) as sum FROM ci_league_result
   GROUP BY user_id ORDER BY sum desc LIMIT ".$page.', '.$per;
  </code></pre>
  
  <p>I'm lookin for it to work something like this:</p>
  
  <pre><code>SELECT COUNT(*) as count, user_id, SUM(earnings) as sum, *NEW-RESULTS-OVERALL-INDEX* AS newindex FROM ci_league_result
  GROUP BY user_id ORDER BY sum desc LIMIT ".$page.', '.$per;
  </code></pre>
  
  <p>notice the AS newindex in the second query.</p>
  
  <p>Thanks for your advice!</p>