I need to use an alias in the WHERE clause, but It keeps telling me that its an unknown column. Is there any way to get around this issue? I need to select records that have a rating higher than x. Rating is calculated as the following alias:
sum(reviews.rev_rating)/count(reviews.rev_id) as avg_rating
You could use a HAVING clause, which can see the aliases, e.g.
but in a where clause you’ll need to repeat your expression, e.g.
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.
From the MySQL Manual: