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

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

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

select dt,dau,round(count(u_info.uid)/dau,2)
from
    (select dt,count(distinct uid) dau
    from
        (
        select date_format(in_time,"%Y-%m-%d")dt,uid
        from tb_user_log
        union all
        select date_format(out_time,"%Y-%m-%d")dt,uid
        from tb_user_log
        )t1
    group by dt
    ) dt_info 
left join
    (
    select uid,min(date_format(in_time,"%Y-%m-%d"))mindt
    from tb_user_log 
    group by uid
    ) u_info on dt_info.dt=u_info.mindt
group by dt,dau
order by dt

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务