当前位置:网站首页>daily sql - user retention rate for two days

daily sql - user retention rate for two days

2022-08-11 07:13:00 Eating too much sugar will not gain weight

Two-day retention rate

Data column:
id device_id quest_id result date


select count(date2) / count(date1) as avg_ret
from
(select distinct d1.device_id, d1.date as date1, d2.date as date2
from question_practice_detail d1
leftjoin(
select distinct device_id, date
from question_practice_detail) d2
on d1.device_id = d2.device_id
and date_add(d1.date, interval 1 days) = d2.date
)a


select avg(if(datediff(date2,date1)= 1,1,0)) as avg_ret
from(
select distinct device_id,date as date1,lead(date) over(partition by device_id orderby date) as date2
from (select distinct device_id,date from question_practice_detail) b
)a

原网站

版权声明
本文为[Eating too much sugar will not gain weight]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110517396253.html