【发布时间】:2019-06-09 21:39:08
【问题描述】:
总结一下我正在尝试做的事情:
我有一堆区域,其中一个包含很多产品。我已经计算了每种产品的折扣,产品的平均折扣(按地区划分)以及它们的标准差(也按地区划分)。
现在,我需要计算一个新的平均折扣(再次按地区划分),但只考虑 discount
的产品select product,
discount,
region,
--this is the line i want to add
avg (case when discont < avg_discount + stddev_discount then discount) over(partition by region) end as new_discount*
from (
select product,
discount,
region,
avg(discount) over (partition by region) as avg_discount,
stddev(discount) over (partition by region) as stddev_discount
from base
)
我想要什么:
【问题讨论】:
-
样本数据和期望的结果会有所帮助。并显示您编写的查询。
标签: sql amazon-redshift window-functions