title: SQL Server case statement in select clause
body: <p>I have a query which gives me StudentId and PercentageScored in Exams which the Student attended, a student can attend multiple exams</p>
  <pre><code>StudentId | PercentageScored
      101         82
      102         57
      101         69
      103         71
      103         42
  </code></pre>
  <p>Below is a sample query, my actual query looks similar to the below.</p>
  <pre><code>Select s.StudentId, m.[PercentageScored]
  FROM dbo.[Student] S
  Inner join dbo.[Marks] m
  ON S.[StudentId] = m.[StudentId]
  WHERE S.[StudentGroup] = 12 AND S.[Active] = 1 
  </code></pre>
  <p>Now i need to add some logic so that my output looks like below</p>
  <pre><code>StudentId  | FirstClass | SecondClass | ThirdClass
     101
     102
     103
     104
  </code></pre>
  <p>If the students PercentageScored is above 80% then 1st class, PercentageScored between 60 to 80 % then 2nd class,PercentageScored  below 60% then 3rd class.. I need to give the counts, for a given student how many times he scored more than 80%, how many times between 60 - 80%, how many times below 60%</p>