如何在MySQL中计算多重移动平均值 [英] How to calculated multiple moving average in MySQL

查看:178
本文介绍了如何在MySQL中计算多重移动平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下表,如何获取5个周期移动平均值,10个周期移动平均值,5个周期指数移动平均值的列.

Using table below, How would get a column for 5 period moving average, 10 period moving average, 5 period exponential moving average.

+--------+------------+
| price  | data_date  |
+--------+------------+
| 122.29 | 2009-10-08 |
| 122.78 | 2009-10-07 |
| 121.35 | 2009-10-06 |
| 119.75 | 2009-10-05 |
| 119.02 | 2009-10-02 |
| 117.90 | 2009-10-01 |
| 119.61 | 2009-09-30 |
| 118.81 | 2009-09-29 |
| 119.33 | 2009-09-28 |
| 121.08 | 2009-09-25 |
+--------+------------+

推荐答案

示例中的5行移动均线将不起作用. LIMIT运算符适用于返回集,而不适用于汇总的行,因此对其进行更改不会影响汇总值.

The 5-row moving average in your example won't work. The LIMIT operator applies to the return set, not the rows being considered for the aggregates, so changing it makes no difference to the aggregate values.

这篇关于如何在MySQL中计算多重移动平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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