Search Postgresql Archives

Re: count( only if true)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 12, 2005 at 22:24:48 +0200,
  peter pilsl <pilsl@xxxxxxxxxxxx> 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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
       message can get through to the mailing list cleanly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux