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

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

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

with data as (
select
    uid,
    min(in_time) time,
    max(out_time) last_login
from
    tb_user_log
group by uid
),
data2 as (
select
*,
case
when timestampdiff(day,time,(select max(out_time) from tb_user_log ))<7 then "新晋用户"
when timestampdiff(day,last_login,(select max(out_time) from tb_user_log ))<7 then '忠实用户'
when timestampdiff(day,last_login,(select max(out_time) from tb_user_log ))<30 then '沉睡用户'
else '流失用户'
end as user_grade
from
data
)
select
user_grade,
round(count(*)/( select count(*) from data   ) ,2)as ratio
from data2
group by user_grade
order by 
ratio desc

全部评论

相关推荐

11-13 12:02
门头沟学院 Java
我要娶个什么名:好骂,好骂 别学计算机就行了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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