题解 | #每天的日活数及新用户占比#

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

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

#简单的判断思路解题,排序判断uid排名第一的登录的时间,再利用case进行判断
with tiaojian as (
select 
uid,
date(in_time) as day
from tb_user_log
group by uid,day
union all
select
uid,
date(out_time) as day
from tb_user_log
group by uid,day
)

select
day,
count(distinct uid) as dau,
round(
count(distinct case when m=1 then uid end)/count(distinct uid),2) as
uv_new_ratio 
from(
select 
uid,
day,
row_number()over(partition by uid order by day ) as m
from tiaojian
) as t 
group by day
order by day

全部评论

相关推荐

白菜小丑呜呜:集美,简历有点问题,+v细嗦
点赞 评论 收藏
分享
怎么起名字:学历不足,
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务