Re: Counting boolean values (how many true, how many false)

Поиск
Список
Период
Сортировка
От Richard Broersma
Тема Re: Counting boolean values (how many true, how many false)
Дата
Msg-id AANLkTin2HC0rvF1vCQk3BxNw0wWbPVAjYSEmMAF-nAqM@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Counting boolean values (how many true, how many false)  (Alexander Farber <alexander.farber@gmail.com>)
Список pgsql-general
On Tue, Nov 16, 2010 at 11:32 AM, Alexander Farber
<alexander.farber@gmail.com> wrote:
> sum(case when good then 1 else 0 end) as good,
> sum(case when not good then 1 else 0 end) as "not good",
> sum(case when fair then 1 else 0 end) as fair,
> sum(case when not fair then 1 else 0 end) as "not fair",
> sum(case when nice then 1 else 0 end) as nice,
> sum(case when not nice then 1 else 0 end) as "not nice"
> from public.pref_rep;

Here is one slightly more compact.
# select
COUNT(NULLIF( good, FALSE)) as good,
COUNT(NULLIF( good, TRUE)) as "not good",
COUNT(NULLIF( fair, FALSE)) as fair,
COUNT(NULLIF( fair, TRUE)) as "not fair",
COUNT(NULLIF( nice, FALSE)) as nice,
COUNT(NULLIF( nice, TRUE)) as "not nice",
from public.pref_rep;

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

В списке pgsql-general по дате отправления:

Предыдущее
От: Alexander Farber
Дата:
Сообщение: Re: Counting boolean values (how many true, how many false)
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: ipv4 data type does not allow to use % assubnet mask delimiter