Re: [GENERAL] aggregate question - Mailing list pgsql-general

From William D. McCoy
Subject Re: [GENERAL] aggregate question
Date
Msg-id 199810221728.NAA01843@aeolus.geo.umass.edu
Whole thread Raw
In response to Re: [GENERAL] aggregate question  (Ulf Mehlig <umehlig@uni-bremen.de>)
List pgsql-general
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

pgsql-general by date:

Previous
From: "Michael A. Koerber"
Date:
Subject: Bug in pg_dump/pg_dumpall handling of CONSTRAINTS?
Next
From: "Mark D. Butler"
Date:
Subject: Postgres SQL Web Page