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

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

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 ;

全部评论

相关推荐

牛客100866号技...:把电科加粗,把电科加粗,把电科加粗,两个吊车尾的项目合并成一个,再加一个管理系统。电科✌🏻在成都面中厂手拿把掐
点赞 评论 收藏
分享
北枳的南橘:建议大家务必去和他沟通一下,像极了小学生对你侃侃而谈国际局势😂
找AI工作可以去哪些公司...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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