Re: Query how-to

From: "Marc Mamin" <M(dot)Mamin(at)intershop(dot)de>
To: "Montaseri" <montaseri(at)gmail(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Query how-to
Date: 2008-10-03 12:20:45
Message-ID: CA896D7906BF224F8A6D74A1B7E54AB30455CE74@JENMAIL01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Hi,

What about something like that ?

select adate, sum(openedCount) as openedCount, sum(closedCount) as closedCount
from
(
select sum(case when status ='Closed' then stop_date else start_date end) as adate,
sum(case when status ='Closed' then 1 else 0 end) as closedCount
sum(case when status ='New' then 1 else 0 end) as openedCount
from Yourtable
where status in ('Closed','New')
)x
group by adate
order by adate

HTH,

Marc

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Raj Mathur 2008-10-03 18:55:31 For each key, find row with highest value of other field
Previous Message Frank Bax 2008-10-02 22:04:51 Re: Query how-to