title: Add a Column in Query
body: <p>Here is my query:</p>
  
  <pre><code>SET @rank=0;
  
  SELECT @rank := @rank +1 AS rank_id, name, SUM(points) AS points
    FROM battle_points
    WHERE category =  'test'
    AND user_id !=0
    GROUP BY user_id
    ORDER BY points DESC; 
  </code></pre>
  
  <p>I'd like to add a column <code>rank</code> based on the total points. With this query, the points are fine but the <code>rank_id</code> virtual column doesn't match up.</p>
  
  <p>For example, the top user with the most points has <code>rank</code> <code>26</code>, yet the <code>rank_id</code> column has a value of <code>24</code>.</p>
  
  <p>How do I matchup the <code>rank_id</code> column with the points column?</p>
  
  <p>Note: while I am fully versed in PHP, I need a solution for MySQL only.</p>