题解 | 计算每个人的平均使用周期

计算每个人的平均使用周期

https://www.nowcoder.com/practice/8487dea5a48f4d14a4b7f69ee6f4c7cc

#公式: 7*登陆天数/最近日期和初次登陆的天数差 为周登陆天数
with a as (select uid, 
min(login_date) as min_dt,
count(distinct login_date) as days from user_login_tb
group by uid),
b as (select max(login_date) cur_dt from user_login_tb)
select a.uid, round(a.days/datediff(b.cur_dt,a.min_dt)*7,2) as active_period from a join b 
order by uid

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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