【发布时间】:2014-03-02 15:24:31
【问题描述】:
我想计算 post_author 的平均结果。这是我的代码:
AVG(CASE WHEN post_author = 1 THEN post_content ELSE 0 END )as avg
在 2 条记录 (100, 66.7) 上得到 100 的结果,应该是 83.35 哪里出了问题?
【问题讨论】:
-
post_auther 和 post_content 是数字列吗?
-
使用
group by post_author进行avg计算有什么问题? -
考虑提供适当的 DDL(和/或 sqlfiddle)以及所需的结果集
-
post_auther 是数字,post_content 不是。 @Ravinder --我需要按其他东西分组。
-
如果
post_content是不是数字,那你为什么用它来计算avg?