我正在尝试编写一个简单的配置单元查询:
select sum(case when pot_sls_q > 2* avg(pit_sls_q) then 1 else 0)/count(*) from prd_inv_fnd.item_pot_sls where dept_i=43 and class_i=3 where p_wk_end_d = 2014-06-28;
在这里 pit_sls_q
以及 pot_sls_q
这两个列都是配置单元表中的列,我需要具有 pot_sls_q
超过平均值的2倍 pit_sls_q
. 但是我得到错误:
失败:semanticexception[error 10128]:行1:95尚未支持udaf“avg”的位置
为了消遣,我甚至尝试使用一些窗口功能:
select sum(case when pot_sls_q > 2* avg(pit_sls_q) over (partition by dept_i,class_i) then 1 else 0 end)/count(*) from prd_inv_fnd.item_pot_sls where dept_i=43 and class_i=3 and p_wk_end_d = '2014-06-28';
考虑到过滤或划分相同条件下的数据本质上是“相同”的数据这一事实,这是很好的,但即使这样,我也会得到错误:
失败:semanticexception[error 10002]:行1:36无效列引用“avg”:(可能的列名为:p\u wk\u end\u d、dept\u i、class\u i、item\u i、pit\u sls\u q、pot\u sls\u q)
请提出正确的方法。
1条答案
按热度按时间qlckcl4x1#
您正在使用
AVG
内部SUM
这将不起作用(连同其他语法错误)。尝试分析
AVG OVER ()
这是: