title: Mysql get position of row after "sum" and "group"
body: <p>I need to get the position of a single player id in this table in 2 different ways on total_points (2 separate queries is fine unless it can be done in 1?)</p>
  
  <p>For example, If <strong>player_id = 1</strong> -  I need to find out their row position from the total points in two ways:</p>
  
  <ol>
  <li>Grouping together and SUM on player_id (includes all season_id and guild_id)</li>
  <li>Grouping together and SUM on player_id with a specific season_id (includes all guild_id)</li>
  </ol>
  
  <p>.</p>
  
  <pre><code>+-----------+-----------+----------+--------------+
  | player_id | season_id | guild_id | total_points |
  +-----------+-----------+----------+--------------+
  |         1 |         1 |        1 |            5 |
  |         2 |         1 |        2 |            6 |
  |         3 |         2 |        1 |            2 |
  ....
  |         1 |         1 |        2 |            4 |
  |         2 |         2 |        2 |            4 |
  |         4 |         1 |        3 |            8 |
  +-----------+-----------+----------+--------------+
  </code></pre>
  
  <p>So in this example I would say <strong>player_id = 1</strong> and the result would return to me position 2 since they have the second highest SUM total_points which in this example is 9 (player 2 has 10).</p>
  
  <p>In another query I need to group the results within a season_id. player_id = 1 and season_id = 1 which should return position 1 since they have 9 which is the highest within the season.</p>
  
  <p>I will need to also limit it down by guild_id later but I assume I can figure that out if I get a query that works using player_id and season_id</p>
  
  <p>Any help would be great so I don't have to do all of this inside PHP and iterating over all the database results which is a waste of resources if it can be done in MySQL since this table will eventually have millions of records.</p>
  
  <p>Thank you.</p>