title: SQL: Count values higher than average for a group
body: <p>How can one use SQL to count values higher than a group average?</p>
  
  <p>For example:</p>
  
  <p>I have table <code>A</code> with:</p>
  
  <pre><code>q   t
  1   5
  1   6
  1   2
  1   8
  2   6
  2   4
  2   3   
  2   1
  </code></pre>
  
  <p>The average for group 1 is 5.25. There are two values higher than 5.25 in the group, 8 and 6; so the count of values that are higher than average for the group is 2.</p>
  
  <p>The average for group 2 is 3.5. There are two values higher than 3.5 in the group, 5 and 6; so the count of values that are higher than average for the group is 2.</p>