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

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

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

# 问题:统计每天的日活数及新用户占比

select
# 统计每天的日活树及新用户占比
    dt,
    count(distinct uid) dau,
    round(
        sum(if (date (first_log) = dt, 1, 0)) / count(distinct uid),
        2
    ) uv_new_ratio
from
    (
        select
            # 每个用户的初次注册时间,活跃时间,去重
            distinct uid,
            first_log,
            date (time) dt
        from
            (
                # 每个用户的初次注册时间
                select
                    uid,
                    min(in_time) first_log
                from
                    tb_user_log
                group by
                    uid
            ) as tb_log
            right join (
                # 每个用户的活跃时间
                select
                    *,
                    in_time time
                from
                    tb_user_log
                union
                select
                    *,
                    out_time time
                from
                    tb_user_log
            ) as tb_user_log using (uid)
    ) as tb_log_information
group by
    dt
order by
    dt

全部评论

相关推荐

06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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