How to get sum of the count of rows till date from table in MySQL
It can be, for example,
SELECT SUM(dates.a_date &gt;= test.on_date AND (dates.a_date &lt; test.off_date OR test.off_date IS NULL)) `count`, 
       dates.a_date `date`
FROM ( SELECT on_date a_date FROM test 
       UNION 
       SELECT off_date FROM test WHERE off_date IS NOT NULL ) dates
CROSS JOIN test
GROUP BY 2
ORDER BY 2;

fiddle
dates subquery generats dates list when the amount of ON ids might have changed.
SUM tests each row against the conditions for particular date and counts the amount of matched rows (testing result is 1 while matching and 0 otherwise).
If some date is absent then look the row with closest lower date.