Re: SQL Question - Using Group By - Mailing list pgsql-general

From Alban Hertroys
Subject Re: SQL Question - Using Group By
Date
Msg-id 45E2ADD2.4070100@magproductions.nl
Whole thread Raw
In response to Re: SQL Question - Using Group By  ("ksherlock@gmail.com" <ksherlock@gmail.com>)
List pgsql-general
ksherlock@gmail.com wrote:
> You could use COUNT() in conjunction with NULLIF:
>
> select "Type",
> count(nullif("Active", false)) as "Active Count",
> count(nullif("Active", true)) as "Inactive Count",
> 100 * count(nullif("Active", false)) / count(*) as "Active Percent"
> from table_name group by "Type"

Tom Lane suggested me to use sum("Active"::int) in a similar situation;
Except that I had boolean expressions instead of values. It is a bit
faster; IMO readability is just "different".

--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
   7500 AK Enschede

// Integrate Your World //

pgsql-general by date:

Previous
From: Dave Page
Date:
Subject: Re: PostgreSQL on Windows Paper
Next
From: RPK
Date:
Subject: Re: problem installing NPGSQL and pgOLEDB with .NET