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

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

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

with t1 as (
    select uid , date_format(in_time,'%Y-%m-%d') as time  from tb_user_log
    union -- 去重
    select uid , date_format(out_time,'%Y-%m-%d') as time  from tb_user_log
), -- 如果in_time-进入时间和out_time-离开时间跨天了,在两天里都记为该用户活跃过
t2 as (
    select *, 
    row_number() over (partition by uid) as rn
    from t1
    ),
t3 as (
    select *,
    case when rn = 1 then time  end  as earliest
    from t2
    )
select time,
       count( distinct  uid) as dau, -- 去重count
       round(count(if(earliest is not null , 1 ,earliest)) / count(1),2 ) as uv_new_ratio
	   -- earliest 不为空 是新用户
from t3 group by time ;

全部评论

相关推荐

点赞 评论 收藏
转发
OPSL:钱确实给的多,但是追责这一点比较迷惑…3个月具体如何计算呢?出勤天数30*3吗?还是21*3呢?万一中间学校有安排怎么办呢?这个得多问一问呀
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务