题解 | #统计活跃间隔对用户分级结果#

统计活跃间隔对用户分级结果

https://www.nowcoder.com/practice/6765b4a4f260455bae513a60b6eed0af

with t as (
        select uid,max(date_format(in_time,"%Y-%***x_date,min(date_format(in_time,"%Y-%m-%d")) min_date
        from tb_user_log
        group by uid
)
select "忠实用户" user_grade,round(sum(if(datediff("2021-11-04",max_date)<7&&datediff("2021-11-04",min_date)>=7,1,0))/count(uid),2) ratio from t
union
select "新晋用户" user_grade,round(sum(if(datediff("2021-11-04",max_date)<7&&datediff("2021-11-04",min_date)<7,1,0))/count(uid),2) ratio from t
union
select "沉睡用户" user_grade,round(sum(if(datediff("2021-11-04",max_date)>=7&&datediff("2021-11-04",max_date)<30,1,0))/count(uid),2) ratio from t
union
select "流失用户" user_grade,round(sum(if(datediff("2021-11-04",max_date)>=30,1,0))/count(uid),2) ratio from t

全部评论

相关推荐

求个公司要我:接好运
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务