title: How to make ranking system in php mysql?
body: <p>I have a php application which has workout table where I am storing daily users workout data based on activity(like: run, walk, cycling). At the end of the month I have to create a leaderboard to generate rank based on highest workout points.</p>
  
  <pre><code>SELECT total_distance, user_id,date_created 
     FROM workouts 
     WHERE date_created LIKE '%2019-11%' AND activity_type='Run'. 
  </code></pre>
  
  <p>with the above query I am getting output as mention below</p>
  
  <p><a href="https://i.stack.imgur.com/bngIN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bngIN.jpg" alt="table output after executing first query"></a></p>
  
  <p>I have optimized the query by using GROUP BY user_id in query.</p>
  
  <pre><code>SELECT SUM(total_distance) as points, user_id,date_created 
      FROM workouts 
      WHERE date_created LIKE '%2019-11%' AND activity_type='Run' 
      GROUP BY user_id
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WJSU4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WJSU4.jpg" alt="table output after executing 2nd query"></a></p>
  
  <p>I want my final output as shown in 2nd image along with rank as new column.
  How to write a query for that. I am not able to do it..</p>