Would someone explain why I can’t seem to use a WHERE clause on my AS variable (not sure what those are actually called.
if i do something like WHERE a.n = gameone in the same exact place it works.
Can i not use a WHERE clause on a var thats created like AVG(b.r) AS fra ?
If i can. how can i?
SELECT
a.id, a.n, a.t, a.d,
AVG(b.r) AS fra, COUNT(b.id) as tvotes
FROM `games` a
LEFT JOIN `games_ratings` b
ON a.id = b.id
WHERE fra >= 2
GROUP BY a.id
ORDER BY a.ts
DESC LIMIT 0, 50
No, the values being selected are not in scope for
WHEREbecause which rows are selected depends on theWHERE. If you really want to do a condition on them, useHAVINGbut note thatHAVINGclauses are not optimized.See the MySQL documentation on SELECT for more information on
HAVING.