Re: columns for count histograms of values

From: Alexy Khrabrov <deliverable(at)gmail(dot)com>
To: chester c young <chestercyoung(at)yahoo(dot)com>
Cc: sql pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: columns for count histograms of values
Date: 2008-05-01 08:35:46
Message-ID: 70FB0CA5-942F-4B73-9722-940E1D4FB15B@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Chester -- awesome! Exactly what the doctor ordered. Just one
syntactic fix needed on 8.3.1:

case when rating=1 then 1 else 0 end

-- etc.

Cheers,
Alexy

On Apr 30, 2008, at 4:12 PM, chester c young wrote:

>
> --- Alexy Khrabrov <deliverable(at)gmail(dot)com> wrote:
>
>> Greetings -- I have a table of the kind
>>
>> Ratings:
>> id integer
>> rating smallint
>>
>> -- where value can take any value in the range 1 to 5. Now I want to
>>
>> have a statistical table Stats of the form
>>
>> id integer
>> min smallint
>> max smallint
>> avg real
>> r1 integer
>> r2 integer
>> r3 integer
>> r4 integer
>> r5 integer
>>
>> -- how can I create it in one pass over Ratings?
>
> select id, min(rating), max(rating), avg(rating),
> sum( case rating = 1 then 1 else 0 end ),
> ...
>
>
>
>
> ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alexy Khrabrov 2008-05-02 21:26:34 numbering rows on import from file
Previous Message Mag Gam 2008-05-01 01:32:51 Re: columns for count histograms of values