How to compute percentages

Поиск
Список
Период
Сортировка
От Sindile Bidla
Тема How to compute percentages
Дата
Msg-id CA+fb49Yfn3X6H+EbBDXZxf9fReRWRtwGkEtOMVpmM5UhhpYKMQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: How to compute percentages  (Humberto Carvalho <carvalho.humberto@gmail.com>)
Список pgsql-novice
I have a query that is like this:

SELECT cl1, count(cl2) as no_accounts, sum(cl2) as consumption
FROM tbl1
WHERE cl2 != 0
GROUP BY cl1
ORDER BY cl1;

this gives me the following output

cl1      no_accounts     consumption
a               2                         50
b               1                         100 
c               5                         30

On the same query i want to calculate percentages no_accounts and consumption without having to create a table or view and then computing the percentages

cl1      no_accounts    percent_no_accounts        consumption             percent_no_consumption
a               2                            25                                      50                                     27
b               1                            12                                     100                                    55 
c               5                           62                                        30                                      16


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

Предыдущее
От: Willy-Bas Loos
Дата:
Сообщение: Re: SELECT FROM 'varying_table'
Следующее
От: Humberto Carvalho
Дата:
Сообщение: Re: How to compute percentages