SELECT count(distinct q2.device_id,q2.date)/count(distinct q1.device_id,q1.date) as avg_ret
FROM question_practice_detail as q1 left outer join question_practice_detail as q2 
on q1.device_id=q2.device_id and datediff(q2.date,q1.date)=1;