title: SQL group students by age from date of birth
body: <p>I have a table "student" that features student's "name" and "DOB".</p>
  
  <p>I would like to group students into the following groups:</p>
  
  <p>a. 10-12<br>
  b. 13-14<br>
  c. 15-16
  d. >= 17</p>
  
  <p>so it would appear</p>
  
  <p>a. paul, peter mary<br>
  b. john, william<br>
  etc.</p>
  
  <p>How would I go about this?</p>
  
  <p>So far I have:</p>
  
  <pre><code> select  case
              when  age between 10 and 12 then a
              when  age between 13 and 14 then b
              when  age between 15 and 16 then c
              when  age &gt;= 17 then d
  
      from    (
              SELECT  ROUND(DATEDIFF(Cast(CURRENT_TIMESTAMP() as Date),
                          Cast(birthday as Date)) / 365, 0) as age
              FROM    db.student 
  </code></pre>
  
  <p>but can't seem to get my head around it.</p>
  
  <p>I am using Management Studio.</p>
  
  <p>Many thanks in advance.</p>