【发布时间】:2022-01-11 19:17:47
【问题描述】:
我想计算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
【问题讨论】:
-
目前我还没有完全理解你的数据结构。相同的
customer_id是否有可能具有不同的avg_total_orders_last_30_days的不同行? -
没有这个表是客户级别的,每个客户只有一个 avg_total_orders_last_30_days 和 avg_total_orders_last_12_months 的值
-
那你为什么要应用任何分组?
-
另外,您能否解释一下 avg_total_orders_last_30_days using the avg_total_orders_last_12_months 的标准偏差是什么意思,即,请给出一些输入和输出示例以及获得输出的公式,如果不是很明显。