SELECT round(count(b.device_id)/count(a.device_id), 4) as avg_ret FROM (SELECT distinct device_id, date FROM question_practice_detail) as a left join (SELECT distinct device_id, date FROM question_practice_detail) as b on a.device_id = b.device_id and a.date = DATE_ADD(b.date,interval 1 day);