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

平均活跃天数和月活人数

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

一、明确需求:

  1. 每月完成作答的用户得平均活跃天数
  2. MAU
#剔除未提交试卷的记录;提取用户年份,年月,年月日作为后续的筛选条件
with
t1 as
(
SELECT distinct *
    , year(start_time) y
    , DATE_FORMAT(start_time,'%Y%m') y_m
    , date_format(start_time,'%Y%m%d') y_m_d
from exam_record
where submit_time is not null 
    )

select y_m as month
    , round(avg(active_days),2) avg_active_days
    , count(distinct uid) mau 
from 
(
select y_m,uid
    ,count(distinct y_m_d) active_days
from t1
where y =2021
group by y_m,uid
    )x 
group by y_m

二、拓展

date_format(date,日期格式) 具体见链接官方文档

全部评论

相关推荐

爱吃肉的伊登在写日记:好棒,27届简历能做成这个样子,但是第一个项目感觉cover住难度还是不小的,特别是二面的时候肯定要对分布式系统设计这一块儿有高出正常面试者的水平才行
点赞 评论 收藏
分享
05-07 19:10
已编辑
中国科学技术大学 C++
silly01:现在先去 momenta,8-9月去鹅找日常实习,八股文算法背好了你这随便进。不过建议补充一下后端知识,MySQL、Redis看下八股,再补个6824,加点go后台的技术栈,9月随便进大厂。CPP后端只能来WXG
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务