Re: columns for count histograms of values - Mailing list pgsql-sql

From chester c young
Subject Re: columns for count histograms of values
Date
Msg-id 357171.1486.qm@web54307.mail.re2.yahoo.com
Whole thread Raw
In response to columns for count histograms of values  (Alexy Khrabrov <deliverable@gmail.com>)
Responses Re: columns for count histograms of values  (Alexy Khrabrov <deliverable@gmail.com>)
List pgsql-sql
--- Alexy Khrabrov <deliverable@gmail.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


pgsql-sql by date:

Previous
From: "Mag Gam"
Date:
Subject: Re: columns for count histograms of values
Next
From: Alexy Khrabrov
Date:
Subject: Re: columns for count histograms of values