Search Postgresql Archives

Re: how to calculate standard deviation from a table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Pierre,

How do you know in which group each row belongs? If you don't care how
the rows are grouped, you can say this:

create table foo (v float);
insert into foo select random() from generate_series(1, 1000000) s(a);
select n % 50 g, stddev(v) from (select row_number() over () n, v from
foo) x group by g;

On the other hand if you have some way of ordering the rows you could say this:

create table foo (id integer, v float);
insert into foo select a, random() from generate_series(1, 1000000) s(a);
select (n - 1) / 50 g, stddev(v), count(*) from (select row_number()
over (order by id) n, v from foo) x group by g order by g;

Yours,
Paul

On Thu, Jan 22, 2015 at 7:18 AM, Pierre Hsieh <pierre.hsieh@xxxxxxxxx> 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



-- 
_________________________________
Pulchritudo splendor veritatis.


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux