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

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

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

with fresher_detail as(
    select 
    uid,
    min(date(in_time)) first_open
    from
        tb_user_log
    group by 1
)
,dau_detail as(
    select uid,
           dau_date
    from
    (
    select
        uid,
        date(in_time) dau_date
    from
        tb_user_log
    union 
    select uid,
           date(out_time) dau_date
    from
        tb_user_log
) k
)
select
    dau_date dt,
    dau,
    round(case when new_users is null then 0 else new_users end/dau,2) uv_new_ratio
from
(
    select
        dau_date,
        count(distinct uid) dau
    from
        dau_detail
    group by 1
) s1
left join
(
    select
        first_open ,
        count(1) new_users
    from fresher_detail
    group by 1

) s2
on s2.first_open = s1.dau_date
order by 1

全部评论

相关推荐

面了100年面试不知...:今年白菜这么多,冬天可以狂吃了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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