SQL29 计算用户的平均次日留存率
描述
题目:现在运营想要查看用户在某天刷题后第二天还会再来刷题的平均概率。请你取出相应数据。示例:question_practice_detail
id | device_id | quest_id | result | date |
1 | 2138 | 111 | wrong | 2021-05-03 |
2 | 3214 | 112 | wrong |
2021-05-09 |
3 | 3214 | 113 | wrong |
2021-06-15 |
4 | 6543 | 111 | right | 2021-08-13 |
5 | 2315 | 115 | right |
2021-08-13 |
6 | 2315 | 116 | right |
2021-08-14 |
7 | 2315 | 117 | wrong |
2021-08-15 |
…… | |
|
|
|
根据示例,你的查询应返回以下结果:
avg_ret |
0.3000 |
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 datediff(t2.date,t1.date) = 1
标签:次日,08,留存,wrong,device,2021,SQL29,date,id From: https://www.cnblogs.com/fulaien/p/17554609.html