sum(bool)? - Mailing list pgsql-sql

From Daniel Wickstrom
Subject sum(bool)?
Date
Msg-id 14998.34183.16811.538101@gargle.gargle.HOWL
Whole thread Raw
In response to sum(bool)?  (Olaf Zanger <olaf.zanger@soli-con.com>)
Responses Re: sum(bool)?  (Andrew Perrin <aperrin@socrates.berkeley.edu>)
List pgsql-sql
>>>>> "Olaf" == Olaf Zanger <olaf.zanger@soli-con.com> writes:
   Olaf> hi there i'd like to add up the "true" values of a   Olaf> comparison like
   Olaf> sum(a>b)
   Olaf> it just doesn't work like this
   Olaf> any workaround

Try using a case statement:

select sum(case when  a > b then 1 else 0 end) ....


-Dan


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: AW: [HACKERS] ask for help !!! (emergency case)
Next
From: Tod McQuillin
Date:
Subject: Re: sum(bool)?