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

平均活跃天数和月活人数

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;

全部评论

相关推荐

06-26 10:08
门头沟学院 C++
北京Golang实习,一个月4700,吃住都不报,公司位置在海淀。请问友友怎么看呢?如果要租房的话有什么建议吗
码农索隆:租房肯定是合租了,剩下的钱,差不多够正常吃饭了,看看能不能学到东西吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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