title: If, Else or Case statement in SQL
body: <p>I want to take the average of row only if the value is greater than zero. However, I am receiving the following error:</p>
  
  <blockquote>
    <p><em>'Column 'Daily.Rad' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY...'</em></p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>SELECT Date,
         AVG([Speed]) as [Speed], 
  
         CASE WHEN [Rad] &gt; 0.0
              THEN AVG([Rad])
              ELSE 0.0
         END AS [Rad], 
  
         AVG([Pressure]) as [Pressure], 
  
         FROM Daily 
  WHERE MONTH(Date) = MONTH('08/31/2011')  
  GROUP BY Date
  </code></pre>