【发布时间】:2013-12-04 06:37:31
【问题描述】:
我在一个名为 transaction 的表中有数据,我得出了购买价值,即 final_rat1 * quantity 和购买数量的总和
Buysell Quantity Final_rat1
B 50 88.14
B 230 88.14
B 75 88.14
B 87 88.14
B 187 88.14
B 150 88.14
B 221 88.14
下面是它的代码,但是当我平均购买价值/购买数量的总和时,我无法获得正确的平均值。你能指导我吗?下面是代码,我已经提到了
sum(case
when sauda.buysell = 'B' then
sauda.quantity * 1
else
0
end) as "P.Qty",
sum(case
when sauda.buysell = 'B' then
sauda.quantity * (sauda.final_rat1 + sauda.brokpercontract)
else
0
end) As "P.value",
sum(case
when sauda.buysell = 'B' then
sauda.quantity * (sauda.final_rat1 + sauda.brokpercontract)/sauda.quantity
else
0
end) as "P.Avg"
实际平均值应为 88.14,其中我得到的平均值为 616.98,如果我从低于平均水平的查询中删除总和
case
when sauda.buysell = 'B' then
sauda.quantity * (sauda.final_rat1 + sauda.brokpercontract)/sauda.quantity
else
0
end as "P.Avg"
它说“不是按功能分组”
【问题讨论】:
-
更新问题,在已发布的表数据中添加
brokpercontract列.. -
sauda.quantity * (sauda.final_rat1 + sauda.brokpercontract)/sauda.quantity 只会给你 sauda.final_rat1 + sauda.brokpercontract 对吗?让你的问题更清楚,这个专栏 brokpercontract 是什么?也添加。