title: sql - @curRow based on column
body: <p>I'm creating rank system so I need to set rank position for every user.<br>
  I do this:  </p>
  
  <pre><code>SELECT  @curRow := @curRow + 1 AS position,
                  Sum(point_user.amount) AS points
  FROM        users u
  JOIN        point_user ON u.id = point_user.user_id
  JOIN    (SELECT @curRow := 0) r
  GROUP BY
  u.id
  ORDER BY
  position ASC
  </code></pre>
  
  <p>And I'm getting:  </p>
  
  <pre><code>+----------+----------+
  | position | points   |
  +----------+----------+
  |        1 | 86       |
  |        2 | 239      |
  |        3 | 45       |
  +----------+----------+
  </code></pre>
  
  <p>Now, how can I set row number, based on points?<br>
  Should looks like:  </p>
  
  <pre><code>+----------+----------+
  | position | points   |
  +----------+----------+
  |        1 | 239      |
  |        2 | 86       |
  |        3 | 45       |
  +----------+----------+
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>SELECT (@curRow := @curRow + 1) as position, 
                  points, 
                  u2.id
  FROM (SELECT Sum(pu.amount) AS points
        FROM users u JOIN
             point_user pu
             ON u.id = pu.user_id
        GROUP BY u.id
        ORDER BY points DESC
  ) upu, users u2
  CROSS JOIN (
              SELECT @curRow := 0
  ) params
  ORDER BY points DESC
  </code></pre>