The following code is probably self explanatory
Lists number of active subscribers 1st of june
select
count(subscribers) as activeSubscribers
from subscriberlist sub
where
to_date('2012-06', 'yyyy-mm')
between sub.firstDayOfSubscription and sub.lastDayOfSubscription
But if I want to get the number of subscribers in the beginning of every month the past year, what could I do (besides changing the date in the query and repeating).
You can generate a list of months as follows:
This would give you the following output:
You can then include that query as an inline view as follows:
I’d probably wrap this in a sproc that accepts @startDate and @endDate parameters to define the date range you’re interested, but I followed your syntax with the date range being defined with strings.
I was playing with this using this SqlFiddle