select count(if(diff=1,1,null))/count(date) avg_ret from (select date,device_id,datediff(date,lag(date)over(partition by device_id order by date)) diff from question_practice_detail group by date,device_id) a ; 首先明确公式,假若第一天来了100个用户,第二天这100用户中只有50个用户过来了,那么次日留存率就是50/100=50%。 第一步:使用lag窗口函数计算昨日来的...