select (sum(if(d=d1,1,0)))/count(device_id) from ( select device_id, lead(date,1,0)over(partition by device_id) d, date_format(date+1,'%Y-%m-%d')as d1 from ( select distinct device_id,date from question_practice_detail order by device_id,date )a )b