虽然我可以通过一个别名的子查询组和秩序,我不能在where子句中使用别名。 我需要使用连接呢?
作品:
SELECT entries.*,
(SELECT avg(value)
FROM `ratings`
WHERE ratings.entry_id = entries.id) as avg_rating
FROM `entries`
ORDER BY avg_rating DESC
失败(“where子句中未知列‘AVG_RATING’”):
SELECT entries.*,
(SELECT avg(value)
FROM `ratings`
WHERE ratings.entry_id = entries.id) as avg_rating
FROM `entries`
WHERE avg_rating < '4.5000' ORDER BY avg_rating DESC