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

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

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





select act_day as dt,
        count(*) as dau,
        round(sum(if_new)/count(*),2) as uv_new_ratio
from(
    select uid, date(in_time) as act_day,
            min(date(in_time)) over(partition by uid) as new_day,
            if(date(in_time)=min(date(in_time)) over(partition by uid) ,1,0) as if_new #当天新用户计为1,否则0
    from tb_user_log
    union 
    select uid, date(out_time) as out_day,
            min(date(in_time)) over(partition by uid),
            if(date(out_time)=min(date(in_time)) over(partition by uid) ,1,0) as if_new #当天新用户计为1,否则0
    from tb_user_log
) as t1
group by act_day
order by act_day

全部评论

相关推荐

01-05 09:14
同济大学 Java
不要盒我呀:我要是9✌🏻我就选保研,保研了大四再找实习,实习之后,如果觉得自己不适合互联网工作模式,还能有其他选择,如果实习后决定了走互联网,也能提升学历提高竞争力
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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