I have a table with columns ACCOUNT_ID, ACTIVE_DATE and INACTIVE_DATE.
Code: Select all
ACCOUNT_ID| ACTIVE_DATE| INACTIVE_DATE
USER1 05/01/15 05/05/15
USER3 05/01/15 05/20/15
USER2 05/07/15 05/20/15
USER1 05/06/15 05/20/15
Code: Select all
select
count(distinct accountid)
from table
where
'05/05/15'
between ACTIVE_DATE
and INACTIVE_DATE
My question is, how do write this looping test in SQL so I can move down a series of dates and count the number of users that are between the active and inactive dates?