题解 | #2021年11月每天新用户的次日留存率#

每天的日活数及新用户占比

http://www.nowcoder.com/practice/dbbc9b03794a48f6b34f1131b1a903eb

from(select uid,date(out_time)ot,
    case when date(in_time)!=date(out_time) then -1
            else 1 end as cnt
from tb_user_log)a2#标记当天活跃且不跨天的用户为1分
union all
select uid,ot,cnt
from(select uid,date(out_time)ot,
       case when date(in_time)!=date(out_time) then 1
            else -1 end as cnt
from tb_user_log)a1#标记当天活跃且跨天的用户为1分
where cnt>0) )#存放临时表,内容是日活跃用户情况
select ot,sc,round(count(u)/sc,2)#将u联结在表后,就可以知道每个日期下的新用户是谁,对u列基于ot分组计数就可以得到每个日期下的新用户人数
from(select ot,sum(cnt)sc
from a3
group by ot)b1#日活总数
left join
(select uid as u,min(ot) ft
from a3
group by uid)b2 on b2.ft=b1.ot#找出每个日期下的新用户是哪位
group by ot
全部评论

相关推荐

05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-01 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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