MySQL Forums
Forum List  »  Newbie

Re: Moving average
Posted by: angel rivero
Date: November 05, 2013 02:30AM

Rick James Wrote:
-------------------------------------------------------
> Is MEDIA() some macro in Excel?
>
> What does "F_SUM" mean? It sounds like it is the
> sum of something. You want the moving average of
> a sum?
>
> I gave you two ways to get moving averages of F1
> and F2. Apply the same principles to F_SUM and
> you will get 62062.50121667.

thank you.

In excel cell I use:
=AVERAGE(F43:F54)

F_SUM is the sum where values in the column F1, F2 and F3

this version of your query working:
mysql> DROP TABLE IF EXISTS `foo`;

CREATE TABLE foo
    SELECT ID,
            F_SUM, @sum1 := @sum1 + F_SUM AS sum1
        FROM `page1-1`
        JOIN  ( SELECT @sum1 := 0
              ) init;

SELECT b.ID,
        ROUND((b.sum1 - a.sum1) / 12,2) AS MA1
    FROM foo a
    JOIN foo b ON a.ID = b.ID - 12;
Query OK, 0 rows affected

Query OK, 53 rows affected
Records: 53  Duplicates: 0  Warnings: 0

+----+-----------+
| ID | MA1       |
+----+-----------+
| 13 | 166258.95 |
| 14 | 166897.94 |
| 15 | 167660.15 |
| 16 | 167511.31 |
| 17 | 166994.22 |
| 18 | 167583.42 |
| 19 | 168596.70 |
| 20 | 169391.35 |
| 21 | 167176.32 |
| 22 | 167176.32 |
| 23 | 167176.32 |
| 24 | 167176.32 |
| 25 | 167176.40 |
| 26 | 167176.48 |
| 27 | 167176.40 |
| 28 | 167176.40 |
| 29 | 167176.32 |
| 30 | 167176.32 |
| 31 | 167176.23 |
| 32 | 167176.23 |
| 33 | 167176.15 |
| 34 | 167176.15 |
| 35 | 167159.47 |
| 36 | 167159.39 |
| 37 | 167159.39 |
| 38 | 167159.39 |
| 39 | 167159.31 |
| 40 | 167159.22 |
| 41 | 167159.30 |
| 42 | 167159.30 |
| 43 | 167159.39 |
| 44 | 160841.91 |
| 45 | 152505.38 |
| 46 | 144680.80 |
| 47 | 135687.00 |
| 48 | 125362.51 |
| 49 | 113103.72 |
| 50 | 100506.61 |
| 51 | 87119.27  |
| 52 | 74416.31  |
| 53 | 62062.50  |
+----+-----------+
41 rows in set



Edited 1 time(s). Last edit at 11/05/2013 02:37AM by angel rivero.

Options: ReplyQuote


Subject
Written By
Posted
October 29, 2013 08:56AM
October 29, 2013 11:51AM
October 30, 2013 02:40AM
October 30, 2013 10:06AM
October 30, 2013 10:24AM
October 30, 2013 01:10PM
November 02, 2013 04:15PM
November 03, 2013 04:18AM
November 03, 2013 10:36PM
November 04, 2013 04:53AM
November 04, 2013 10:52PM
Re: Moving average
November 05, 2013 02:30AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.