题解 | #统计活跃间隔对用户分级结果#
统计活跃间隔对用户分级结果
https://www.nowcoder.com/practice/6765b4a4f260455bae513a60b6eed0af
select name,round(count(*)/(select count(distinct uid) from tb_user_log),2) rate from ( select ( case when if(datediff((select date(max(in_time)) from tb_user_log),min_date)<7,1,0) then '新晋用户' when if(datediff((select date(max(in_time)) from tb_user_log),max_date)<7,1,0) then '忠实用户' when if(datediff((select date(max(in_time)) from tb_user_log),max_date)>29,1,0) then '流失用户' else '沉睡用户' end ) name from ( select uid,date(max(in_time)) max_date,date(min(in_time)) min_date from tb_user_log group by uid )t1 )t2 group by name order by rate desc;