Re: count( only if true)

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: peter pilsl <pilsl(at)goldfisch(dot)at>
Cc: Martín Marqués <martin(at)bugs(dot)unl(dot)edu(dot)ar>, PostgreSQL List <pgsql-general(at)postgresql(dot)org>
Subject: Re: count( only if true)
Date: 2005-10-27 04:46:51
Message-ID: 20051027044651.GA19670@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 12, 2005 at 22:24:48 +0200,
peter pilsl <pilsl(at)goldfisch(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Garamond 2005-10-27 05:30:28 Re: Why database is corrupted after re-booting
Previous Message Michael Fuhr 2005-10-27 04:38:03 Re: Error Message