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

平均活跃天数和月活人数

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

-- 按照月分组,group by month(submit_time)
-- 平均月活跃天数(avg_active_days)=活跃总次数数/uid,保留两位小数,round(字段,2)
-- 活跃总次数=交卷次数,submit_time is not null
-- 月度活跃人数mau=count( distinct uid),按照月份分组
select date_format(submit_time,'%Y%m') as month,
round((count(distinct uid,date_format(submit_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 date_format(submit_time, '%Y%m');

下面这个只对了两个测试用例,因为count(date_format(submit_time,'%y%m%d')))/count(distinct uid)这里前一个count没有对uid去重,正确的是count(distinct uid,date_format(submit_time,'%y%m%d')))/count(distinct uid)

-- 按照月分组,group by month(submit_time)
-- 平均月活跃天数(avg_active_days)=活跃总次数数/uid,保留两位小数,round(字段,2)
-- 活跃总次数=交卷次数,submit_time is not null
-- 月度活跃人数mau=count( distinct uid),按照月份分组
select date_format(submit_time,'%Y%m') as month,
round((count(date_format(submit_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 date_format(submit_time, '%Y%m');



下面一个的结果 alt

DATE_FORMAT() 用法详解

全部评论

相关推荐

10-09 00:50
已编辑
长江大学 算法工程师
不期而遇的夏天:1.同学你面试评价不错,概率很大,请耐心等待;2.你的排名比较靠前,不要担心,耐心等待;3.问题不大,正在审批,不要着急签其他公司,等等我们!4.预计9月中下旬,安心过节;5.下周会有结果,请耐心等待下;6.可能国庆节前后,一有结果我马上通知你;7.预计10月中旬,再坚持一下;8.正在走流程,就这两天了;9.同学,结果我也不知道,你如果查到了也告诉我一声;10.同学你出线不明朗,建议签其他公司保底!11.同学你找了哪些公司,我也在找工作。
点赞 评论 收藏
分享
微风不断:兄弟,你把四旋翼都做出来了那个挺难的吧
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务