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

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

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

with a2 as(
with a1 as(
select uid,min(date(in_time)) early,max(date(in_time)) recent
from tb_user_log
group by uid)
select uid
,case when datediff('2021-11-04',early) > 6 and datediff('2021-11-04',recent) <=6 then '忠实用户'
when datediff('2021-11-04',early) <=6 and datediff('2021-11-04',recent) <=6 then '新晋用户'
when datediff('2021-11-04',recent)>6 and datediff('2021-11-04',early) <=29 then '沉睡用户' 
when datediff('2021-11-04',recent) > 29 then '流失用户' end user_grade
from a1
)
select user_grade,
round(count(user_grade)/(select count(*) from a2),2) ratio
from a2
group by user_grade
order by ratio desc;

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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