title: ActiveRecord average value from last n rows
body: <p>I'm attempting to average the last n rows in a column in an activerecord query like so:</p>
  
  <pre><code>Points.where(player_id: &lt;player_id&gt;).limit(5).average(:points)
  </code></pre>
  
  <p>but it gives me the same answer as if I leave the limit out like:</p>
  
  <pre><code>Points.where(player_id: &lt;player_id&gt;).average(:points)
  </code></pre>
  
  <p>If I test without the .average(:points) then I get only five rows, but it seems the average is ignoring this. </p>
  
  <p>Any help much appreciated!</p>