title: Average of grouped data in column using Sequelize
body: <p>I'm trying to find the average of a 'ratings' column for all the data that has the same 'VenueId'. I have it working with raw code but need to adapt it in Sequelize. The working raw code is                                                     </p>
  
  <pre><code>SELECT venueId, AVG(rating) AS average FROM reviews GROUP BY VenueId
  </code></pre>
  
  <p>The code I've tried is  </p>
  
  <pre><code>Review.findAll({
      order: [[Sequelize.fn('AVG', Sequelize.col('rating'))]]
  }).then(function(Venues) {})
  </code></pre>
  
  <p>I'm getting an error: </p>
  
  <blockquote>
    <p>Executing (default): SELECT id, review, rating, createdAt, updatedAt,
    VenueId FROM Reviews AS Review ORDER BY max(rating); Unhandled
    rejection SequelizeDatabaseError: UNKNOWN_CODE_PLEASE_REPORT:
    Expression #1 of ORDER BY contains aggregate function and applies to
    the result of a non-aggregated query.</p>
  </blockquote>
  
  <p>Any ideas?             </p>