Re: average/stddev on all values returned by a select distinct - Mailing list pgsql-general

From Michael Fuhr
Subject Re: average/stddev on all values returned by a select distinct
Date
Msg-id 20070717135100.GA18571@winnie.fuhr.org
Whole thread Raw
In response to average/stddev on all values returned by a select distinct  (ann hedley <ann.hedley@ed.ac.uk>)
Responses Re: average/stddev on all values returned by a select distinct
List pgsql-general
On Tue, Jul 17, 2007 at 01:51:21PM +0100, ann hedley wrote:
> What I want is the average and stddev of the set of lengths returned by
> this query.  Something like...
>
> select average(select distinct on (id) length(consensus) from cluster
> order by id,length(consensus) desc);

I think this is what you're looking for:

select avg(length)
  from (
    select distinct on (id) length(consensus)
      from cluster
     order by id, length(consensus) desc
  ) s;

--
Michael Fuhr

pgsql-general by date:

Previous
From: ann hedley
Date:
Subject: average/stddev on all values returned by a select distinct
Next
From: Tom Lane
Date:
Subject: Re: Limitations on 7.0.3?