Re: How to compute percentages
От
Oliveiros d'Azevedo Cristina
Тема
Re: How to compute percentages
Дата
Msg-id
36695DD8501F4BF59C7BD38140FAF78E@marktestcr.marktest.pt
Список
Дерево обсуждения
How to compute percentages Sindile Bidla <sindile.bidla@gmail.com>
Re: How to compute percentages Humberto Carvalho <carvalho.humberto@gmail.com>
Hi,
Sindile,
Could you please try this variation of your own query, please?
Best,
Oliver
SELECT cl1, count(cl2) as no_accounts,
count(cl2) * 100.0 / (SELECT count(cl2) FROM tbl1) as percent_no_accounts,
sum(cl2) as consumption,
sum(cl2) * 100.0 / (SELECT sum(cl2) FROM tbl1) as percent_no_consumption
FROM tbl1
WHERE cl2 != 0
GROUP BY cl1
ORDER BY cl1;
----- Original Message -----From: Sindile BidlaTo: pgsql-noviceSent: Wednesday, May 23, 2012 12:23 PMSubject: [NOVICE] How to compute percentagesI have a query that is like this:SELECT cl1, count(cl2) as no_accounts, sum(cl2) as consumptionFROM tbl1WHERE cl2 != 0GROUP BY cl1ORDER BY cl1;this gives me the following outputcl1 no_accounts consumptiona 2 50b 1 100c 5 30On the same query i want to calculate percentages no_accounts and consumption without having to create a table or view and then computing the percentagescl1 no_accounts percent_no_accounts consumption percent_no_consumptiona 2 25 50 27b 1 12 100 55c 5 62 30 16
В списке pgsql-novice по дате отправления