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

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

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

全部评论

相关推荐

挣K存W养DOG:入职送金条全球游,路过缅甸停一下🐔
点赞 评论 收藏
分享
过往烟沉:我说什么来着,java就业面就是广!
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务