题解 | #计算每个人的平均使用周期#
key: 理解什么叫平均使用周期 ,即 登录次数/(最后一次登录时间-首次登陆时间)
周平均使用周期=7*平均使用周期
select uid, round(7*active_day/timestampdiff(day,t.first_day,t1.last_day),2) as active_period from ( select uid, count(distinct login_date) as active_day, min(login_date) as first_day from user_login_tb group by uid )t join (select max(login_date) as last_day from user_login_tb) t1 order by uid