title: Can you divide one alias by another in MySQL?
body: <p>I have a multi-table query, similar to this (simplified version)</p>
  
  <pre><code>SELECT columns, count(table2.rev_id) As rev_count, sum(table2.rev_rating) As sum_rev_rating 
  FROM table1
  LEFT JOIN table2
  ON table1.dom_id = table2.rev_domain_from 
  WHERE dom_lastreview != 0 AND rev_status = 1 
  GROUP BY dom_url 
  ORDER BY sum_rev_rating/rev_count DESC
  </code></pre>
  
  <p>The problem is in the <code>ORDER BY</code> clause. This causes a MySQL error to show, which is as follows:</p>
  
  <blockquote>
    <p>Reference 'sum_ rev_ rating' not supported (reference to group function)</p>
  </blockquote>