Re: count( only if true) - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: count( only if true)
Date
Msg-id 20051027044651.GA19670@wolff.to
Whole thread Raw
In response to Re: count( only if true)  (peter pilsl <pilsl@goldfisch.at>)
List pgsql-general
On Wed, Oct 12, 2005 at 22:24:48 +0200,
  peter pilsl <pilsl@goldfisch.at> wrote:
>
> knowledge=# select x,count(case when id<5 then 't' else null end) from
> test2 group by x;
>  x | count
> ---+-------
>  e |     1          <--------- thats the result I want !!!
>  b |     1
>  c |     1
>  d |     0
>  a |     1
> (5 rows)

For simple cases like this you probably want to do the following:
SELECT x, count(*) FROM test2 WHERE id < 5 GROUP BY x

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Error Message
Next
From: David Garamond
Date:
Subject: Re: Why database is corrupted after re-booting