[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: [GENERAL] aggregate question
From:       "William D. McCoy" <wdmccoy () geo ! umass ! edu>
Date:       1998-10-22 17:28:04
[Download RAW message or body]

Ulf,  As a partial answer to your question about statistical functions 
and std. deviation in particular, I have pulled out an example query
that I have used in the past as an example:


select lab_no, prep_no, avg(hai), max(hai), min(hai),
|/((sum(hai^2)-(count(hai)::float8)*(avg(hai)^2))/count(hai)::float8)
	as stdhai, count(hai), peak_values
from hyd_ratios
group by peak_values, lab_no, prep_no;


The expression on the second line of the query returns the standard
deviation of my data "hai" (which is float8) in this case.  Note that
count returns an integer that must be cast as float8.  One could
retrieve the variance in a similar way.  These are awkward to type,
but I usually keep queries in text files that I send to psql on a
command line.  Of course, a nice set of statistical functions would be
welcome.

-- 
William D. McCoy
Geosciences
University of Massachusetts
Amherst, MA  01003

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic