Re: how to calculate standard deviation from a table

From: Rémi Cura <remi(dot)cura(at)gmail(dot)com>
To: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to calculate standard deviation from a table
Date: 2015-01-22 16:28:30
Message-ID: CAJvUf_u90d3HgRhX3K1BphPDyRbBxRPz1DeoUAajF_JkfJy6tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Are you sur you don't want a moving windows
(stddev on 0 to 50 , then stdev on 1 to 51)
..

If you don't want moving windows your query would look like

DROP TABLE IF EXISTS your_data;
CREATE TABLE your_data AS
SELECT s as gid , random() as your_data_value
FROM generate_series(1,10000) as s ;

SELECT min(gid) as min_gid, max(gid) as max_gid, stddev(your_data_value) as
your_stddev
FROM your_data
GROUP BY (gid-1)/50
ORDER BY min_gid ASC

Please note that "min(gid) as min_gid, max(gid) as max_gid" and "ORDER BY
min_gid ASC" are just there to help you understand the result
Cheers,
Rémi-C

2015-01-22 16:49 GMT+01:00 David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>:

> Pierre Hsieh wrote
> > Hi
> >
> > This table just has a column which type is integer. There are one million
> > data in this table. I wanna calculate standard deviation on each 50 data
> > by
> > order. It means SD1 is from data 1 to data 50, SD2 is from data 51 to
> > 100.... Is there anyone who can give me some suggestions? Thanks
> >
> > Pierre
>
> Integer division
>
> David J.
>
>
>
> --
> View this message in context:
> http://postgresql.nabble.com/how-to-calculate-standard-deviation-from-a-table-tp5835031p5835042.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul Jungwirth 2015-01-22 16:32:29 Re: how to duplicate data for few times by SQL command in PG
Previous Message Paul Jungwirth 2015-01-22 16:28:06 Re: how to calculate standard deviation from a table