Re: Calculating a moving average - Mailing list pgsql-general

From Dann Corbit
Subject Re: Calculating a moving average
Date
Msg-id D425483C2C5C9F49B5B7A41F89441547055836@postal.corporate.connx.com
Whole thread Raw
In response to Calculating a moving average  ("Vanole, Mike" <Mike.Vanole@cingular.com>)
Responses Re: Calculating a moving average  ("Jim C. Nasby" <decibel@decibel.org>)
List pgsql-general

Why not use a cursor?

 

P.S.

A moving average will look much better if you Hahn the tails.


To do a normal 7 point moving average, you take (x[i]+ x[i+1]+ x[i+2]+ x[i+3]+ x[i+4]+ x[i+5]+ x[i+6])/7 as point xprime[i] and (y[i]+ y[i+1]+ y[i+2]+ y[i+3]+ y[i+4]+ y[i+5]+ y[i+6])/7 as point yprime[i].

 

But when you start let x[0], y[0] be the first point, and then average the next 2 for the second point… until you get to 7 and then do the same thing in the other end.  Otherwise, you get a very strange looking curve.

 

IMO-YMMV


From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Vanole, Mike
Sent: Wednesday, January 19, 2005 1:34 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Calculating a moving average

 

Hi,

 

I need to calculate a moving average and I would like to do it with SQL, or a Pg function built for this purpose. I'm on Pg 7.4. Is this possible in Pg without a bunch of self joins, or is there a funtion available?

 

Thanks,

Mike

pgsql-general by date:

Previous
From: Wes
Date:
Subject: Re: Shared memory and Mac OS X
Next
From: "Jim C. Nasby"
Date:
Subject: Re: Calculating a moving average