题解 | #平均活跃天数和月活人数#

平均活跃天数和月活人数

http://www.nowcoder.com/practice/9e2fb674b58b4f60ac765b7a37dde1b9

/*
select
    ym,
    round(count(uid) / count(distinct uid ), 2) as avg_active_days,
    count(distinct uid )as mau
from
    (select 
        uid,
        exam_id,
        date(submit_time),
        concat(year(submit_time),  LPAD(month(submit_time),2,'0') )  as ym,
        row_number() over(partition by uid, date(submit_time) order by submit_time) as rk
    from exam_record 
    where submit_time is not null and year(submit_time) = 2021) a
where rk=1
group by ym
*/

-- 参考《要成为一个厉害的人》的代码,更好
select DATE_FORMAT(start_time,"%Y%m") as month,
round(count(distinct uid,date_format(start_time,"%Y%m%d"))/count(distinct uid),2) as avg_active_days,
count(distinct uid) as mau
from exam_record
where submit_time is not NULL
and YEAR(submit_time) =2021
group by month;

全部评论

相关推荐

10-07 23:57
已编辑
电子科技大学 Java
八街九陌:博士?客户端?开发?啊?
点赞 评论 收藏
分享
粗心的雪碧不放弃:纯学历问题,我这几个月也是一直优化自己的简历,后来发现优化到我自己都觉得牛逼的时候,发现面试数量也没有提升,真就纯学历问题
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务