Can you use an alias in the WHERE clause in mysql?

You could use a HAVING clause, which can see the aliases, e.g. HAVING avg_rating>5 but in a where clause you’ll need to repeat your expression, e.g. WHERE (sum(reviews.rev_rating)/count(reviews.rev_id))>5 BUT! Not all expressions will be allowed – using an aggregating function like SUM will not work, in which case you’ll need to use a HAVING clause. … Read more

SQL – HAVING vs. WHERE

WHERE clause introduces a condition on individual rows; HAVING clause introduces a condition on aggregations, i.e. results of selection where a single result, such as count, average, min, max, or sum, has been produced from multiple rows. Your query calls for a second kind of condition (i.e. a condition on an aggregation) hence HAVING works … Read more