Subject | Re: SQL query help |
---|---|
Author | bill_zwirs |
Post date | 2006-09-18T05:22:58Z |
> Isn't it just a simple count query on both occasions?Adam
>
> select count(*)
> from table
> where createdate >= :FirstDayOfMonth
> and createdate < :FirstDayOfNextMonth
>
> -- an index on createdate would assist this query
>
> select count(*)
> from table
> where ceasedate >= :FirstDayOfMonth
> and ceasedate < :FirstDayOfNextMonth
>
> -- an index on ceasedate would assist this query
>
> Or if you were desperate to get them in a single query,
>
> select
> (
> select count(*)
> from table
> where createdate >= :FirstDayOfMonth
> and createdate < :FirstDayOfNextMonth
> ) as CreateCount
> ,
> (select count(*)
> from table
> where ceasedate >= :FirstDayOfMonth
> and ceasedate < :FirstDayOfNextMonth
> ) as CeaseCount
> from RDB$DATABASE
>
> Adam
>
Maybe I didn't make my question very clear, but I want the result
grouped by month so that, for example, a 1 year period the result
would show for each month, number of customers created, number of
customers made inactive.
The end result of the query is to be shown in a graph that will then
also show the net gain/loss of customers (per month). That's why I
would like to be able to do this in a single query.
thanks
Bill