title: Rank Scores_leetcode #178
body: <p>Could someone help explain how to solve this question? I am a beginner of sql and don't know how to use variables.</p>
  
  <p>Write a SQL query to rank scores given Scores table. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" between ranks.</p>
  
  <p><a href="https://i.stack.imgur.com/DvgFL.png" rel="noreferrer">Question Description</a></p>
  
  <p><a href="https://leetcode.com/problems/rank-scores/description/" rel="noreferrer">https://leetcode.com/problems/rank-scores/description/</a></p>
  
  <p>I have looked the solutions in the discussion forum but still can't understand the logic behind it. It would be greatly appreciated if someone can provide step by step explanations.
  One of the possible solutions is like (without variables):</p>
  
  <pre><code>select scores.Score, count(ranking.Score) as Rank
  from scores, (select distinct Score from scores) ranking
  where ranking.score&gt;=scores.Score
  group by scores.Id
  order by scores.Score desc
  </code></pre>
  
  <p>Thanks!</p>