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

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

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

#有些复杂


select 
    t2.dt dt
    ,t3.cnt1 dau
    ,ifnull(t2.ratio,0.00) nv_new_ratio
from
(
select 
    t11.dt
    ,round(t000.cnt2/t11.cnt1,2) ratio
from
(select 
    dt 
    ,count(distinct uid) cnt1
from 
(select uid,date(in_time) dt from tb_user_log 
union 
select uid,date(out_time) dt from tb_user_log ) t1
group by dt
) t11 
left join
(
select 
    dt
    ,count(distinct uid) cnt2
from
(
select 
    uid 
    ,dt 
    ,row_number()over(partition by uid order by dt) rk
from 
(
select uid,date(in_time) dt from tb_user_log 
union 
select uid,date(out_time) dt from tb_user_log 
) t0
) t00 
where rk=1 
group by dt 
) t000 
on t11.dt=t000.dt
) t2
left join 
(select 
    dt 
    ,count(distinct uid) cnt1
from 
(select uid,date(in_time) dt from tb_user_log 
union 
select uid,date(out_time) dt from tb_user_log ) t1
group by dt) t3 
on t2.dt=t3.dt
order by 1

全部评论

相关推荐

11-02 09:49
已编辑
货拉拉_测试(实习员工)
热爱生活的仰泳鲈鱼求你们别卷了:没事楼主,有反转查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务