题解 | #计算用户的平均次日留存率#
计算用户的平均次日留存率
https://www.nowcoder.com/practice/126083961ae0415fbde061d7ebbde453
select sum(if(day_diff=1,1,0))/count(distinct device_id, date) as avg_ret from(
select device_id, date, timestampdiff(day,lag(date,1)over(partition by device_id order by date),date)day_diff
from question_practice_detail
)t1