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

From: ann hedley <ann(dot)hedley(at)ed(dot)ac(dot)uk>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: average/stddev on all values returned by a select distinct
Date: 2007-07-17 14:04:59
Message-ID: 469CCC8B.9020602@ed.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Fuhr wrote:
> 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;
>
>
Thank you, it was indeed.

--
Ann

"In a world without walls and fences - who needs Windows and Gates ?"
(unknown)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-07-17 14:07:18 Re: Limitations on 7.0.3?
Previous Message Michael Fuhr 2007-07-17 13:51:00 Re: average/stddev on all values returned by a select distinct