title: Make AVG() ignore 0's?
body: <p>I have a column where I can get 0 values, but I need to calculate the average of that column without counting those 0's as part of the divider.</p>
  
  <p>I have the following query:</p>
  
  <pre><code>SELECT AVG(CAST(RATING AS NUMERIC(18, 2))) AS AVERAGE,
         QUESTIONID,
         Questions.SHORTVERSION,
         COUNT(CASE
                   WHEN RATING &gt; 0
                   THEN 1
                   ELSE NULL
               END) AS COUNT
  FROM AnswersRating
       INNER JOIN Questions ON Questions.ID = QUESTIONID
  WHERE SURVEYID IN
  (
      SELECT ID
      FROM SURVEYS
      WHERE FLIGHTDATAID = '8371'
  )
  GROUP BY QUESTIONID,
           Questions.SHORTVERSION
  ORDER BY QUESTIONID;
  </code></pre>
  
  <p>I read somewhere that I can use <code>NULLIF</code> to help this, but I couldn't figure out how to use it correctly. Anyone who can help me out?</p>