Re: SQL Question - Using Group By

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: SQL Question - Using Group By
Дата
Msg-id 45E2ADD2.4070100@magproductions.nl
обсуждение исходный текст
Ответ на Re: SQL Question - Using Group By  ("ksherlock@gmail.com" <ksherlock@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Dave Page
Дата:
Сообщение: Re: PostgreSQL on Windows Paper
Следующее
От: RPK
Дата:
Сообщение: Re: problem installing NPGSQL and pgOLEDB with .NET