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

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

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

#rihuo == mei tian , distinct, yonghuzongshu
#xinyonghu zhanbi=dangtian xinyonghu /rihuo
with tnew as (
    select date(tb.in_time) as date_in_time,count(distinct tb.uid) as newnb
    from tb_user_log tb
    where not exists(
        select 1
        from tb_user_log tbefore
        where tb.uid=tbefore.uid and date(tbefore.in_time)<date(tb.in_time)
    )
    group by date(tb.in_time)
), 
tdate as (
    select tb.uid as uid,date(tb.in_time) as in_time
    from tb_user_log tb
    union
    select tb.uid,date(tb.out_time)
    from tb_user_log tb   )



select date(tb.in_time) as dt, count(distinct tb.uid) as dau,coalesce(round(avg(t.newnb)/count(distinct uid),2),0) as uv_new_ratio
from tdate tb left join tnew t on date(tb.in_time) = t.date_in_time 
group by date(tb.in_time)
order by date(tb.in_time) asc





全部评论

相关推荐

迷茫的大四🐶:都收获五个了,兄弟那还说啥,不用改了,去玩吧
点赞 评论 收藏
分享
10-09 17:17
已编辑
门头沟学院 Java
活泼的代码渣渣在泡池...:同学你好,我也是学院本,后天要面这个亚信科技,是实习,请问问题都啥样呀,我项目就做了网上的,这是第一次面试
投递多益网络等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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