From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Joseph Syjuco <joseph(at)asti(dot)dost(dot)gov(dot)ph> |
Cc: | postgres <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: variance aggregate function incorrect? Reference Materials |
Date: | 2002-06-24 16:16:36 |
Message-ID: | 200206241616.g5OGGa504236@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Joseph Syjuco wrote:
> hi
> i needed the variance function ... i dont know if i introduced the wrong
> parameters or maybe this variance is not the variance that im looking
> for but it doesnt provide the right results
>
> variance=(nEx^2 - (Ex)^2)/(n(n-1))
> my sql statement
> select variance(answer) from tbl_answer (where answer is of type
> integer)
>
> because of this i need to create my own variance aggregate (unless
> someone enlightens me on whats happening with the variance aggregate) so
> i would like to know if theres anyone who knows a good create aggregate
> tutorial (with samples) ... all i got from google so far is the
> reference from ninthwonder.com
Uh, I tried this:
test=> select variance(relnatts) from pg_class;
variance
---------------
24.4259169884
(1 row)
Not sure if it is the right number or not. Have you tried taking the
square root and see if that number is correct.
The docs say:
The variance is the square of the standard deviation. The
supported data types and result types are the same as for
standard deviation.
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Eckermann | 2002-06-24 18:06:18 | Re: assign count() result to a declared variable in plpgsql |
Previous Message | Tom Lane | 2002-06-24 16:12:33 | Re: assign count() result to a declared variable in plpgsql |