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

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

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

-- 分级 活跃间隔 各活跃等级用户占比 
with t1 as (select count(distinct case when datediff(current_time1,max_time) <= 6 and datediff(current_time1,min_time) > 6 then uid else null end) zhongshi_label,
count(distinct case when datediff(current_time1,max_time) <=6 and datediff(current_time1,min_time) <= 6 then uid else null end) xinji_label,
count(distinct case when datediff(current_time1,max_time) >6 and datediff(current_time1,min_time) > 6 then uid else null end) chenshui_label,
count(distinct case when datediff(current_time1,max_time) >29 and datediff(current_time1,min_time) > 29 then uid else null end) liushi_label
from (select uid,
max(in_time) over () current_time1,
min(in_time) over (partition by uid) min_time,
max(in_time) over (partition by uid) max_time,
in_time,out_time
from tb_user_log) t0)

select '忠实用户' user_grade,round(zhongshi_label/(zhongshi_label+xinji_label+chenshui_label),2) ratio from t1
union all 
select '新晋用户' user_grade,round(xinji_label/(zhongshi_label+xinji_label+chenshui_label),2) ratio from t1
union all 
select '沉睡用户' user_grade,round((chenshui_label - liushi_label)/(zhongshi_label+xinji_label+chenshui_label),2) ratio from t1
union all 
select '流失用户' user_grade,round(liushi_label/(zhongshi_label+xinji_label+chenshui_label),2) ratio from t1

全部评论

相关推荐

10-25 12:05
已编辑
湖南科技大学 Java
若梦难了:我有你这简历,已经大厂乱杀了
点赞 评论 收藏
分享
10-06 12:46
门头沟学院 Java
跨考小白:定时任务启动
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务