SQL移动平均线 [英] SQL moving average

查看:349
本文介绍了SQL移动平均线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code>日期点击
2012-05-01 2,230
2012-05-02 3,150
2012-05-03 5,520
2012-05-04 1,330
2012-05-05 2260
2012-05-06 3,540
2012-05-07 2,330

Date Clicks 3 day Moving Average 2012-05-01 2,230 2012-05-02 3,150 2012-05-03 5,520 4,360 2012-05-04 1,330 3,330 2012-05-05 2,260 3,120 2012-05-06 3,540 3,320 2012-05-07 2,330 3,010

所需表格或输出:

 解决方案 


推荐答案

Adjust the DateAdd component of the ON-Clauses to match whether you want your moving average to be strictly from the past-through-now or days-ago through days-ahead. 

调整ON-Clauses的DateAdd组件以匹配您是否希望移动平均值严格从过去到现在还是在过去的几天前。


  • 这适用于您只需要少数几个数据点即可获得移动平均值的情况。

  • 这不是移动多个数据点的平均值的最佳解决方案。

    • This works nicely for situations where you need a moving average over only a few data points.
    • This is not an optimal solution for moving averages with more than a few data points.

    这篇关于SQL移动平均线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆