Re: average/stddev on all values returned by a select distinct

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: ann hedley <ann(dot)hedley(at)ed(dot)ac(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: average/stddev on all values returned by a select distinct
Date: 2007-07-17 13:51:00
Message-ID: 20070717135100.GA18571@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message ann hedley 2007-07-17 14:04:59 Re: average/stddev on all values returned by a select distinct
Previous Message ann hedley 2007-07-17 12:51:21 average/stddev on all values returned by a select distinct