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

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Calculate a quotient for a count of boolean values (true or false)
Date: 2013-06-11 10:33:13
Message-ID: CAADeyWiSp_TRqp+PLWBg_Uy5sANJAgqtaJtgEkhwtHi2QajCjA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

On Tue, Jun 11, 2013 at 11:59 AM, Alban Hertroys <haramrae(at)gmail(dot)com> wrote:
> Because you're calculating a - (b/c) instead of (a-b)/c

> On 11 June 2013 11:51, Alexander Farber <alexander(dot)farber(at)gmail(dot)com> wrote:
>> http://stackoverflow.com/questions/17040692/calculate-a-quotient-in-one-table-and-store-it-in-another-table

right, sorry! But now I have -1,0,1 only:

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
-------------------------+--------
DE10019 | 0
DE10030 | 1
DE10047 | 0
DE10049 | 1
DE10051 | 0
DE10059 | -1
DE10062 | 0
DE10067 | -1
DE10072 | -1

Regards
Alex

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2013-06-11 10:57:10 Re: Calculate a quotient for a count of boolean values (true or false)
Previous Message Alban Hertroys 2013-06-11 09:59:55 Re: Calculate a quotient for a count of boolean values (true or false)