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

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

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

with today as
(select max(out_time) as t from tb_user_log),
lastday as
(select *
from 
(
select *, 
		if(min(in_time) over (partition by uid) = in_time,1,0) as new_act
from tb_user_log
) q
where (uid,in_time) in (select uid,max(in_time) 
						from tb_user_log
						group by uid)
)
select user_grade,
		round(count(user_grade) /sum(count(user_grade)) over (),2) as ratio				
from
(
select lastday.*,
         case
		 when out_time>= date_sub(today.t,interval 6 day) and out_time <= today.t  and new_act = 0 then '忠实用户' 
		 when out_time>= date_sub(today.t,interval 6 day) and out_time <= today.t  and new_act = 1 then '新晋用户' 
		 when out_time< date_sub(today.t,interval 6 day)  and out_time>= date_sub(today.t,interval 29 day) then '沉睡用户' 
		 when out_time< date_sub(today.t,interval 29 day) then '流失用户' 
		 end as user_grade
from lastday,today
) t
group by user_grade
order by ratio desc;
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
苍蓝星上艾露:给它们能的,一群dinner牛马挥刀向更弱者罢了。我写的开源求职AI co-pilot工具,优化你的简历,找到你匹配的岗位,定制你的简历,并让你做好面试准备https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
我的简历长这样
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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