Firstly, you should have a table that contains the year, month details in yyyyMM
format. Then you would need to join that table with the users table with yyyyMM portion of date_start
less than the value in the months table and date_end
greater than or equal to the value in the months table.
This would count a user who was active for more than one month, once per each month, which I think is what you expect.
CREATE TABLE months(yearMonth INT);
INSERT INTO months VALUES(201201);
INSERT INTO months VALUES(201202);
INSERT INTO months VALUES(201203);
....
SELECT m.yearMonth, COUNT(*)
FROM
months m, users u
WHERE
m.yearMonth >= CONVERT(INT,
CONVERT(VARCHAR(4), DATEPART(yy, date_start) +
CONVERT(VARCHAR(2), DATEPART(mm, date_start)
)
AND m.yearMonth <= CONVERT(INT,
CONVERT(VARCHAR(4), DATEPART(yy, date_end) +
CONVERT(VARCHAR(2), DATEPART(mm, date_end)
)
Note: This is SQL Server but you should be able to get the MySQL counterpart for CONVERT/DATEPART functions, I guess.