title: rewrite sql statement with max and groupby in ruby
body: <p>I have this my sql view:</p>
  
  <pre><code>SELECT
      `reports`.`date` AS `date`,
      `reports`.`book_title` AS `book_title`,
      max(
          `reports`.`royalty_type`
      ) AS `royalty_type`,
      max(
          `reports`.`avg_list_price`
      ) AS `avg_list_price`
  FROM
      `reports`
  GROUP BY
      `reports`.`date`,
      `reports`.`book_title`,
      `reports`.`marketplace`
  </code></pre>
  
  <p>As far as I understand it groups results by date, then, by book_title and then by market place and then it selects max <code>royalty_type</code> and <code>avg_list_price</code> within this small subgroups</p>
  
  <p>How do I rewrite this in rails activerecord?
  I don't know how to select max within this small groups in activerecord.</p>