错误代码:1054。“字段列表”中的未知列“喜欢”

时间:2018-10-27 15:56:42

标签: mysql mysql-error-1064

我的要求是平均水平。

mychart.Activate
 With mychart
    .Height = rng.Height
        .Width = rng.Width
        .Chart.Paste
        .Chart.Export Filename:=strTempfile, Filtername:="PNG"      
    End With
mychart.Delete

注意:仅使用单个查询即可获取平均值。

1 个答案:

答案 0 :(得分:4)

can't reference your previous aliases,因此您需要写出完整的语句:

SELECT 
    COALESCE(SUM(type = 1), 0) AS likes,
    COALESCE(SUM(type = 2), 0) AS dislikes,
    count(type) as total_like,
    COALESCE(SUM(type = 1), 0) / COALESCE(SUM(type = 1), 0) AS average,
    e_id  
FROM `e_rating` 
group by e_id 
order by e_id ASC