Calculate a quotient for a count of boolean values (true or false)

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Calculate a quotient for a count of boolean values (true or false)
Date: 2013-06-11 09:51:40
Message-ID: CAADeyWi0_DsBtj5oUMT91bdL2=qJqh2Z+QnhJ3ZpX34GQDYghw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!

In a PostgreSQL 8.4.13 why doesn't this please
deliver a floating value (a quotient between 0 and 1):

select
id,
count(nullif(nice, false)) - count(nullif(nice, true)) /
count(nice) as rating
from pref_rep where nice is not null
group by id
;
id | rating
-------------------------+--------
DE10072 | -1
DE10086 | 18
DE10087 | 1
DE10088 | -1
DE10095 | 276
DE10097 | 37
DE10105 | 5

I am trying to calculate a sum of ratings
given by users to each other
to draw a pie chart in a game, more details here:

http://stackoverflow.com/questions/17040692/calculate-a-quotient-in-one-table-and-store-it-in-another-table

Thank you

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2013-06-11 09:59:55 Re: Calculate a quotient for a count of boolean values (true or false)
Previous Message Toby Corkindale 2013-06-11 06:58:13 Re: PSA: If you are running Precise/12.04 upgrade your kernel.