Re: [GENERAL] aggregate question

From: "William D(dot) McCoy" <wdmccoy(at)geo(dot)umass(dot)edu>
To: Ulf Mehlig <umehlig(at)uni-bremen(dot)de>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] aggregate question
Date: 1998-10-22 17:28:04
Message-ID: 199810221728.NAA01843@aeolus.geo.umass.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mark D. Butler 1998-10-22 18:38:52 Postgres SQL Web Page
Previous Message Michael A. Koerber 1998-10-22 13:03:56 Bug in pg_dump/pg_dumpall handling of CONSTRAINTS?