Re: Question about a query with two count fields - Mailing list pgsql-general

From George Pavlov
Subject Re: Question about a query with two count fields
Date
Msg-id 8C5B026B51B6854CBE88121DBF097A8601215FA6@ehost010-33.exch010.intermedia.net
Whole thread Raw
In response to Question about a query with two count fields  (Jeff Lanzarotta <delux256-postgresql@yahoo.com>)
Responses Re: Question about a query with two count fields
Re: Question about a query with two count fields
List pgsql-general
select
  to_char(ts, 'MM/DD/YYYY') as "day",
  str,
  proc,
  sum(case when z!=0 then 1 end) as good,
  sum(case when z =0 then 1 end) as bad
from foobar
where str != 99999
group by 1,2,3
order by 1
;


> -----Original Message-----
> From: pgsql-general-owner@postgresql.org
> [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Jeff
> Lanzarotta
> Sent: Tuesday, September 11, 2007 8:51 AM
> To: PostgreSQL GENERAL List
> Subject: [GENERAL] Question about a query with two count fields
>
> Hello,
>
> I am in need of producing a query that has two count fields
> in it... Something like:
>
> select to_char(ts, 'MM/DD/YYYY') as "day", str, proc,
> (select count (*) as good from foobar where z != 0),
> (select count (*) as bad from foobar where z = 0)
> from foobar
> where str != 99999
> group by str, day, proc order by str
>
> From this query, the output should look something like this:
>
> day            | str  |  proc  | good |  bad
> 09/10/2007 | 1    |  xyz   |    1   |   3
> 09/10/2007 | 1    |  abc   |    3   |   2
> 09/10/2007 | 2    |  xyz   |    3   |   5
> 09/10/2007 | 2    |  abc   |    1   |   2
>
> I hope I have explained the situation...
>
> I appreciate the help...
>
> Thanks.
>
>
> -Jeff
>

pgsql-general by date:

Previous
From: "George Pavlov"
Date:
Subject: creating/dropping tables inside functions?
Next
From: "Rodrigo De León"
Date:
Subject: Re: Question about a query with two count fields