SQL help - multiple aggregates

Поиск
Список
Период
Сортировка
От hamann.w@t-online.de
Тема SQL help - multiple aggregates
Дата
Msg-id wolfgang-1160818105624.A021691@noten19.local
обсуждение исходный текст
Ответы Re: SQL help - multiple aggregates  (Francisco Olarte <folarte@peoplecall.com>)
Re: SQL help - multiple aggregates  (Ladislav Lenart <lenartlad@volny.cz>)
Re: SQL help - multiple aggregates  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
Hi,

I have a table cv with custid and vendid columns. Every entry represents the purchase of a product
available from a specific vendor.
Now, for a set of "interesting" vendors, I would like to select a new table
custid, c415, c983, c1256
based upon part queries
select custid, count(vendid) as c415 from cv where vendid = 415 group by custid

The only way i managed to achieve that was

select distinct custid into temp table cv1 from cv;
alter table cv1 add column c415 int;
update cv1 set c415 = part.c415 from
 (select custid, count(vendid) as c415 from cv where vendid = 415 group by custid) part
 where cv1.custid = part.custid;
and repeating the process for every column requested

Is there a better way (by creating an aggregate function, perhaps)

Regards
Wolfgang




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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: PGPASSWORD - More than one in a bash script
Следующее
От: Vik Fearing
Дата:
Сообщение: Re: Re: Easiest way to compare the results of two queries row by row and column by column