天天看点

统计日留存及周留存

有时为了查看用户的质量,次日留存,1周内的日留存,周留存率都是用得比较多的统计指标

例1:计算某日注册用户1周内的日留存数据

select CONVERT(varchar(10),targetdate,120),gap,count(distinct t02.uid1) as retentionnum from(

select RegTime as targetdate,Id as uid1 from t_user where DATEDIFF(day,RegTime,'2020-7-17')=0)t01 

left join

(select userid as uid1,datediff(day,'2020-7-17',InitTime)as gap from t_userlog where InitTime between 

'2020-7-17' and '2020-7-24')t02 on t01.uid1=t02.uid1 group by CONVERT(varchar(10),targetdate,120),gap

order by gap asc

例2:计算某周注册用户1月内的周留存数据