题解 | #SQL29 计算用户的平均次日留存率

计算用户的平均次日留存率

http://www.nowcoder.com/practice/126083961ae0415fbde061d7ebbde453

select count(m1.device_id)
/
(select count(m.date) from (select distinct y.date,y.device_id,y.question_id,y.result from question_practice_detail y) m)
from
(select distinct a.device_id, a.date, c.date as 'cdate'
from question_practice_detail a
left join 
(select b.device_id, b.date #date_sub(b.date,interval 1 day) as cdate
 from question_practice_detail b) c
on a.device_id = c.device_id 
where
(convert(substring_index(a.date,'-',-1),SIGNED) 
 - convert(substring_index(c.date,'-',-1),SIGNED)) = 1 and
month(a.date) = month(c.date)) m1


全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
08-20 19:41
那一天的Java_J...:简历完全流水账,学生思维很严重,还有很大的优化空间,可以多看看牛客的简历。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务