From: | Alban Hertroys <alban(at)magproductions(dot)nl> |
---|---|
To: | "ksherlock(at)gmail(dot)com" <ksherlock(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: SQL Question - Using Group By |
Date: | 2007-02-26 09:52:18 |
Message-ID: | 45E2ADD2.4070100@magproductions.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
ksherlock(at)gmail(dot)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(at)magproductions(dot)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 //
From | Date | Subject | |
---|---|---|---|
Next Message | RPK | 2007-02-26 10:25:53 | Re: problem installing NPGSQL and pgOLEDB with .NET |
Previous Message | Dave Page | 2007-02-26 09:32:11 | Re: [GENERAL] PostgreSQL on Windows Paper |