SELECT pairs.startDate, pairs.endDate, DATEDIFF(pairs.endDate, pairs.startDate) + 1 as count FROM
(SELECT t1.date as startDate, MIN(t3.date) as endDate FROM statistics as t1
LEFT JOIN statistics t2 ON t1.date - t2.date = 1 and t2.done = 1
AND DATEDIFF(t1.date, t2.date) = 1
LEFT JOIN statistics as t3 ON t1.date <= t3.date and t3.done = 1
LEFT JOIN statistics as t4 ON DATEDIFF(t3.date, t4.date) = -1 and t4.done = 1
WHERE t1.done = 1 AND ISNULL(t2.date) AND ISNULL(t4.date)
GROUP BY t1.date) as pairs
ORDER BY pairs.startDate