Ok so starting under select date range, I have a question regarding the logic on how this should come out.
I have to check that all members of my enrollmenthistory table are active for a certain month. The fields I have to deal with are subclientcode, policyholderid and suffixid

then I have enroll dates and disenroll dates
so my fields look like this

client phid sid enroll date disenroll date

the first thing I have to check is to make sure there are active members for that group (scc+phid+sid)

I want to break it down by month. so I would use date_format(enroll_date '%Y %m) to isolate the year and the date.

If someone could help with this syntax I use mySQL 5.5, and perhaps my logic is wrong too.

I have to take into consideration that there is an active member for one month but may not be active the next month, and may be active again the following month. Like insurance for union members.
Or the member may be active for only part of a month.

any help or questions to clarify would be greatly appreciated.

Thanks in advance.

ALSO KEEP IN MIND

I have used this query before, but min and max wont work because of the specific date ranges I need to keep in mind.

SELECT sub_client_cd, Enroll_date, Disenroll_Date, COUNT(*) as n
FROM big_pink.enrollment_test
WHERE Enroll_date < '2010-02-01' and (Disenroll_date is null or disenroll_date > '2010-01-01')
GROUP BY sub_client_cd;

How can I loop this using SQL, or would it be easier to throw it in a Python Script?