title: Average and Case in SQL
body: <p>I am trying to generate a report and the following  code does not produce the desired results which gives me 2 lines rather than one.  </p>
  
  <p>The ScoreTypeID could have values of 22, 52, 3 or 4 .   if it is 22 or 52, I need the average and if not I need to show 0.  Any idea what may be the problem ?  Thanks.</p>
  
  <pre><code>  CASE WHEN FAS1.ScoreTypeID = 22 THEN avg(fas1.totalscore)  
         WHEN FAS1.ScoreTypeID = 52 THEN avg(fas1.totalscore)   ELSE 0    
    END  AS   'Total Score',   
  </code></pre>