题解 | #计算用户的平均次日留存率#
计算用户的平均次日留存率
http://www.nowcoder.com/practice/126083961ae0415fbde061d7ebbde453
select count(q2.device_id)/count(q1.device_id) as avg_ret
from (select distinct device_id,date from question_practice_detail) as q1
left join (select distinct device_id,date from question_practice_detail) as q2
on q1.device_id=q2.device_id and q2.date = date_add(q1.date,interval 1 day)
1.left Join: q1为今天的,q2的,用left就是今天的用户,明天还在; 2.date_add(time,interval )操作日期的