title: Change the average grouped calculation for a table
body: <p>quick question because I'm getting crazy on this issue.
  I have a table where I save a lot of analytics data, and I have to put this data on a table. </p>
  
  <p>Every record has this structure:</p>
  
  <pre><code>id: 1,
  user_id: 4,
  store_id: 490,
  company_id: 1,
  completed_courses_percentage: 87
  </code></pre>
  
  <p>At this moment I'm grouping the user by company and then I use the average method to create a table with the average completed course percentage grouped by company.</p>
  
  <p><code>UserActivity.group(:company_id).average(:completed_courses_percentage)</code></p>
  
  <p>If I have three person for a company and the averages are 0, 50 and 100 the total average now is 50%.</p>
  
  <p>By the way I need to change the way I calculate this average: I must calculate the average of people that belong to a company with a completed_courses_percentage > 70.</p>
  
  <p>I try to use</p>
  
  <pre><code>UserActivity.group(:company_id).having("completed_courses_percentage &gt; 70")
  </code></pre>
  
  <p>but the result is 0.</p>