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

平均活跃天数和月活人数

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

-- 方法1 -- 一次聚合,需要进一步理解用户平均活跃天数这个指标,即所有用户当月总活跃天数/用户人数,同时懂得count函数内多字段的巧妙用法,即通过count(distinct uid,date_format(start_time,'%Y%m%d')来计算所有用户当月总活跃天数。 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 score is not null and year(start_time)='2021' group by month order by month; -- 方法2 -- 两次聚合,思考比方法1少但是繁琐,需要两次聚合,容易出错。 select a.month,round(avg(a.day),2) as avg_active_days,count(distinct a.uid) as mau from( select uid,date_format(start_time,'%Y%m') as month,count(distinct left(start_time,10)) as day from exam_record where score is not null group by date_format(start_time,'%Y-%m'),uid ) a where left(a.month,4)='2021' group by a.month order by a.month;

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 14:08
点赞 评论 收藏
分享
06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
下个早班:秒挂就是不缺人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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