title: Best way to perform a subquery in Ruby + Rails when getting an average?
body: <p>Trying to get this query using ActiveRecord, how would I write it properly?</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT AVG(IF(condition)) AS average_id 
  FROM (SELECT * FROM `table`
  WHERE `id` = 1 
  ORDER BY `date` DESC
  LIMIT 10) `table`;
  </code></pre>