columns for count histograms of values

Поиск
Список
Период
Сортировка
От Alexy Khrabrov
Тема columns for count histograms of values
Дата
Msg-id 824FF9F9-9997-4AD9-9955-3CA658E150D4@gmail.com
обсуждение исходный текст
Ответы Re: columns for count histograms of values  ("Mag Gam" <magawake@gmail.com>)
Re: columns for count histograms of values  (chester c young <chestercyoung@yahoo.com>)
Список pgsql-sql
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?  I can use min(),  
max(), avg() for 

insert into stats values (id,select min(rating), max(rating),  
avg(rating), ...) from ratings

-- but what to do for r1,..,r5, short of subselects (select  
count(rating) from ratings where stats.id=ratings.id) for each, which  
is an overkill?

Also, if a table Stats already exists with some more columns, and we  
need to do an update, not insert, for the above, how would that work --

update stats set min=min(ratings), ... from ratings where  
stats.id=ratings.id -- how do we do the histogram in this case, where  
the id is fixed explicitly?

Cheers,
Alexy


В списке pgsql-sql по дате отправления:

Предыдущее
От: Jean-David Beyer
Дата:
Сообщение: Re: Curious about wide tables.
Следующее
От: "Mag Gam"
Дата:
Сообщение: Re: columns for count histograms of values