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

2021年11月每天新用户的次日留存率

http://www.nowcoder.com/practice/1fc0e75f07434ef5ba4f1fb2aa83a450

小白 实际工作中的思路做法,请大牛们多多指教。
利用,虚拟表把每位UID最早的登录时间查出来(表1),在用虚拟表把所有信息时间保存出来,因为有一条件24时之后也算之前的活跃度,所以要考虑到end所以2个时间合并,且重复不合并用union
 之后,取出最早时间,用户登录时间,时间差求出来,在相除即可
with date1 as 
(
select uid,min(date(in_time)) as first_time from tb_user_log
    group by uid
)

date2 as 
(
select  uid ,date(in_time) as sdate from tb_user_log
union 
select  uid ,date(out_time) as sdate from tb_user_log
)


select
t1.first_time,
round(
day1/day0,2)
from
(
select 
t.first_time,
sum(case when t.diff=0 then 1 else 0 end) as day0,
sum(case when t.diff=1 then 1 else 0 end) as day1
from(
select 
date1.first_time,
date2.sdate,
date2.uid,
datediff(date2.sdate,date1.first_time) as diff
from date1 left join date2 on date1.uid=date2.uid
) as t
where
t.first_time like "2021-11%"
group by t.first_time
) as t1
order by t1.first_time
 
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 18:05
哈哈哈哈哈感觉朋友找工作的已经疯掉了,直接上图
码农索隆:真老板娘:“我嘞个去,这不我当年的套路吗
点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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