虽然我可以对别名子查询进行分组和排序,但我不能在 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