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

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

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

select

user_grade,

round(count(user_grade)/(select count(*) from (select 

uid,

case when dt is not null and first_id is not null and dt != first_id then '忠实用户' 

when dt = first_id then '新晋用户'

when dt is null and datediff((select max(date(in_time)) from tb_user_log),first_id) >=7 

and datediff((select max(date(in_time)) from tb_user_log),first_id) <30 then '沉睡用户'

else '流失用户' end 'user_grade'

from

(select distinct 

b.uid,

dt,

first_id

from 

(select uid,date(in_time) dt from tb_user_log

where datediff((select max(date(in_time)) from tb_user_log),date(in_time)) <=6

order by dt) a

right join

(select uid,min(date(in_time)) first_id from tb_user_log group by uid) b

on a.uid = b.uid) c) e),2) ratio

from

(select 

uid,

case when dt is not null and first_id is not null and dt != first_id then '忠实用户' 

when dt = first_id then '新晋用户'

when dt is null and datediff((select max(date(in_time)) from tb_user_log),first_id) >=7 

and datediff((select max(date(in_time)) from tb_user_log),first_id) <30 then '沉睡用户'

else '流失用户' end 'user_grade'

from

(select distinct

b.uid,

dt,

first_id

from 

(select uid,date(in_time) dt from tb_user_log

where datediff((select max(date(in_time)) from tb_user_log),date(in_time)) <=6

order by dt) a

right join

(select uid,min(date(in_time)) first_id from tb_user_log group by uid) b

on a.uid = b.uid) c) d

group by user_grade

order by ratio desc;

全部评论

相关推荐

06-19 13:40
武汉大学 Java
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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