题解 | 次日留存率
牛客每个人最近的登录日期(三)
http://www.nowcoder.com/practice/16d41af206cd4066a06a3a0aa585ad3d
- 次日留存率
-
select round(count(distinct l2.user_id)/count(distinct l1.user_id),3) from (select *,min(date) dat from login group by user_id )l1 left join login l2 on l1.user_id = l2.user_id and l1.dat = date_add(l2.date,interval -1 day)
- round(,3) 四舍五入,小数点后三位
- (select * min(date) from login group by user_id) l1 #每个用户第一次登陆的时间
- left join login l2 on l1.user_id = l2.user_id and l1.min(date) =add_date(l1.min(date), interval -1 day) #left join 第二天登陆的user_id