我的要求是得到平均的喜欢。
SELECT
COALESCE(SUM(type = 1), 0) AS likes,
COALESCE(SUM(type = 2), 0) AS dislikes,
count(type) as total_like,
likes / dislikes, // Error on this line
e_id
FROM `e_rating`
group by e_id
order by e_id ASC
注意:仅使用单个查询获取平均值。
1条答案
按热度按时间ukqbszuj1#
您不能引用以前的别名,因此需要写出完整的语句: