Re: [SQL] Query how-to

2008-10-03 Thread Marc Mamin
this was silly from me! this should naturally look like this: select 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 fro

Re: [SQL] Query how-to

2008-10-03 Thread Marc Mamin
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(cas

Re: [SQL] Query how-to

2008-10-02 Thread Frank Bax
Montaseri wrote: Given table T1 and columns id, start_date, stop_date and status, propose a query that reports count of items opened and closed . status is an enum including NEW, xxx, , CLOSED. The first status of an item is NEW (could be used in place of start_date) For example Date

Re: [SQL] Query how-to

2008-10-02 Thread Richard Broersma
On Thu, Oct 2, 2008 at 1:49 PM, Montaseri <[EMAIL PROTECTED]> wrote: > I was wondering if you can help me with the following query. > > Given table T1 and columns id, start_date, stop_date and status, propose a > query that reports count of items opened and closed . status is an enum > including NE

[SQL] Query how-to

2008-10-02 Thread Montaseri
Hi, I was wondering if you can help me with the following query. Given table T1 and columns id, start_date, stop_date and status, propose a query that reports count of items opened and closed . status is an enum including NEW, xxx, , CLOSED. The first status of an item is NEW (could be used i