SQL Question - Group By and % results per row

Поиск
Список
Период
Сортировка
От Mike
Тема SQL Question - Group By and % results per row
Дата
Msg-id 1173729191.574675.81760@30g2000cwc.googlegroups.com
обсуждение исходный текст
Ответы Re: SQL Question - Group By and % results per row  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-general
I have a SQL statement that uses group-by to generate reports as such:


GroupField        Clicks
----------------        -----------
Page 1              50
Page 2              20
Page 3              30

Now, as an added field, I also want it to tell me what percent of
total clicks each row represents.

GroupField        Clicks             Percent
----------------        -----------           ------------
Page 1              50                   50%
Page 2              20                   20%
Page 3              30                   30%

How do I get access to the total of all clicks on per row basis so I
can divide it? The only solution that comes to my mind is create a
subquery that does a (select count(*) from... where... ) of the
original grouped by sql statement.

Thank you for your help in advance,
Regards,
Mike


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

Предыдущее
От: Stefan Berglund
Дата:
Сообщение: Re: Is This A Set Based Solution?
Следующее
От: Alan J Batsford
Дата:
Сообщение: pg_dumpall and version confusion