SQL汇总日期范围
谁回答这个,非常感谢您!
这是我的数据的一个小片段:
DATE Score Multiplier Weighting
2022-01-05 3 4 7
2022-01-05 4 7 8
2022-01-06 5 2 4
2022-01-06 3 4 7
2022-01-06 4 7 8
2022-01-07 5 2 4
这些数据的每一行都是“发生”的事情,并且在同一天发生多个事件。
我需要做的是在过去3个月中以这些数据的滚动平均值。
因此,仅在2022-01-05中,我的加权平均(调整后)是:
DATE ADJUSTED
2022-01-05 [(3*4) + (4*7)]/(7+8)
除了我在过去的三个月内需要这样做(所以在2022年1月5日,我需要加权平均值 - 使用“加权”列 - 前3个月也可以使用前90天。
不知道这是否足够清楚,但会很感激任何帮助。
谢谢你!
Whoever answers this thank you so, so much!
Here's a little snippet of my data:
DATE Score Multiplier Weighting
2022-01-05 3 4 7
2022-01-05 4 7 8
2022-01-06 5 2 4
2022-01-06 3 4 7
2022-01-06 4 7 8
2022-01-07 5 2 4
Each row of this data is when something "happened" and multiple events occur during the same day.
What I need to do is take the rolling average of this data over the past 3 months.
So for ONLY 2022-01-05, my weighted average (called ADJUSTED) would be:
DATE ADJUSTED
2022-01-05 [(3*4) + (4*7)]/(7+8)
Except I need to do this over the previous 3 months (so on Jan 5, 2022, I'd need the rolling weighted average -- using the "Weighting" column -- over the preceding 3 months; can also use previous 90 days if that makes it easier).
Not sure if this is a clear enough description, but would appreciate any help.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确解释了这一点,我相信一个询问的组将满足需求:
示例数据
查询
结果
db<> fiddle
7c120d161f3d0ff45eb3dde3d9b5e50d零值问题查询Ablove
IF I have interpreted this correctly I believe a GROUP BY query will meet the need:
sample data
query
result
db<>fiddle here
Note: I have not attempted to avoid possible divide by 0 or any NULL value problems in the query ablove