我想计算一下avg_total_orders_last_30_days using the avg_total_orders_last_12_months的标准差。
样本表
customer_id | avg_total_orders_last_30_days | avg_total_orders_last_12_months
939 103 94
441 107 118
082 313 293这就是我迄今尝试过的:
select
customer_id
avg_total_orders_last_30_days,
avg_total_orders_last_12_months,
approx_distinct(SUM(avg_total_orders_last_12_months)) OVER (partition by customer_id ) as stdev_rep
from table
group by 1发布于 2021-12-09 07:51:14
我认为这就是您想要做的,但是您的avg_total_orders_last_12_months字段包含的数字太大,不能用作approx_distinct的“e”。
approx_distinct(x,e)→bigint#
返回不同输入值的近似数目。这个函数提供了计数的近似(不同的x)。如果所有输入值为空,则返回零。此函数应产生不超过e的标准误差,这是所有可能集上(近似正态分布)误差分布的标准差。它不保证对任何特定输入集的错误都有上限。这个函数的当前实现需要在0.0040625,0.26000__的范围内。
如果您希望获得字段的真正样本标准差,请使用STDDEV(x),如下所示:
https://stackoverflow.com/questions/70247894
复制相似问题