Re: How to compute percentages
От | Humberto Carvalho |
---|---|
Тема | Re: How to compute percentages |
Дата | |
Msg-id | CABORsQOGk6mKH25E4OjzSFB0XiSTh0AX9DNhYe7-J4z0=iW_NQ@mail.gmail.com обсуждение исходный текст |
Ответ на | How to compute percentages (Sindile Bidla <sindile.bidla@gmail.com>) |
Список | pgsql-novice |
Try something like this
--
Humberto Carvalho
select acl1, no_accounts , Round(100*counter/total,2) as percentage
from (select count(1) as no_accounts , cl1
from xpto t
where xxxx) x ,
(select count(1) as total
from abc t
where xxxxx) y;
Best regards,
HC
On 23 May 2012 12:23, Sindile Bidla <sindile.bidla@gmail.com> wrote:
I 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
Humberto Carvalho
В списке pgsql-novice по дате отправления: