SQL29 计算用户的平均次日留存率
思路:自连接
首先对两个表针对(用户,日期去重),然后on对相同用户作为条件开启连接,接着使用and过滤时间间隔为1的记录,最后比较两个表的记录数
select count(t2.date)/count(t1.date) from (select distinct device_id,date from question_practice_detail) t1 left join (select distinct device_id,date from question_practice_detail) t2 on t1.device_id = t2.device_id and t2.date = date_add(t1.date,interval 1 day)

浙公网安备 33010602011771号