title: sql case statement of case results
body: <p>I want to take letter grades convert to a number average and then convert back to a letter.
  The</p>
  <pre><code>select 
    avg(case when grade = 'A' then 4
             when grade = 'B' then 3
             when grade = 'C' then 2
             when grade = 'F' then 1 end)
  from student
  where id = 'test'
  </code></pre>
  <p>this works perfectly
  I want to now convert the average back to a letter.</p>
  <p>I tried and it works but I cant help but think there isn't a better easier way to accomplish this</p>
  <pre><code>select case(when (select 
    avg(case when grade = 'A' then 4
             when grade = 'B' then 3
             when grade = 'C' then 2
             when grade = 'F' then 1)
  from student where id = 'test') = 4 then 'A' 
  </code></pre>