当前位置:网站首页>How to analyze the weekly activity rate?
How to analyze the weekly activity rate?
2022-08-03 16:11:00 【monkey data analysis】
【题目】
有两张表:
1)“用户登录信息表”,包含2个字段:用户id、登录日期.
2)“Registered user information form”,包含2个字段:用户id、注册日期.
【问题】Calculate the weekly active user rate.
【解题思路】
1. 活跃用户率
“活跃用户率”It is a common indicator to observe user activity,Generally refers to the proportion of active users among all registered users.When the active period is set to “周”时,计算的就是“Weekly active user rate”.
Weekly active user rate = 周活跃用户数 / The current number of registered users
值得注意的是,“The current number of registered users”Refers to the number of registered users as of the last day of the week.因为,Users registered after this will certainly not be active this week.
2. 日期处理
为了获取“用户登录信息表”中“登录日期”Information for the corresponding week,We need to do something with this field.
函数yearThe role is the year of the date,使用方法是:
year(日期字段名)
函数week的作用是返回一个int型的数值,Represents the week number information of the specified date in the current year,使用方法是:
week(日期字段名,参数)
其中,“参数”不填写的情况下,默认值为0,Sunday is the first day of the week;“参数”为1时,Means Monday is the first day of the week;“参数”为2时,Represents Tuesday as the first day of the week;以此类推.
select 用户id,
登录日期,
year(登录日期) as 年份,
week(登录日期,1) as 周数
from 用户登录信息表;
返回结果如下:
The result is recorded as a tablet1,On this basis, the number of weekly active users is calculated.
select t1.年份,
t1.周数,
count(distinct 用户id) as 活跃用户数
from
(
select 用户id,
登录日期,
year(登录日期) as 年份,
week(登录日期,1) as 周数
from 用户登录信息表
) as t1
group by t1.年份,t1.周数;
返回结果如下:
The result is recorded as a tablet2,The number of active users per week is recorded.
对“Registered user information form”的“注册日期”字段进行处理:
select 用户id,
注册日期,
year(注册日期) as 年份,
week(注册日期,1) as 周数
from Registered user information form;
返回结果如下:
The result is recorded as a tablet3.
for later calculations“The current number of registered users”,需要获取“用户登录信息表”中的“Most active year”,以及对应的“Active maximum weeks”.
select year(max(登录日期)) as Most active year,
week(max(登录日期),1) as Active maximum weeks
from 用户登录信息表;
返回结果如下:
The result is recorded as a tablet4.
3. 多表联结
In order to calculate each active week“The current number of registered users”,将表t3和表t4进行联结.
select count(distinct t3.用户id) as The current number of registered users
from
(
select 用户id,
注册日期,
year(注册日期) as 年份,
week(注册日期,1) as 周数
from Registered user information form
) as t3
left join
(
select year(max(登录日期)) as Most active year,
week(max(登录日期),1) as Active maximum weeks
from 用户登录信息表
) as t4 on 1 = 1
where t3.年份 < t4.Most active year or (t3.年份 = t4.Most active year and t3.周数 <= t4.Active maximum weeks);
返回结果如下:
The result is recorded as a tablet5.
最后,将表t2和表t5联结,计算最终结果:
select t2.年份,
t2.周数,
t2.活跃用户数,
t5.The current number of registered users,
t2.活跃用户数/t5.The current number of registered users as Weekly active user rate
from
(
select t1.年份,
t1.周数,
count(distinct 用户id) as 活跃用户数
from
(
select 用户id,
登录日期,
year(登录日期) as 年份,
week(登录日期,1) as 周数
from 用户登录信息表
) as t1
group by t1.年份,t1.周数
) as t2
left join
(
select count(distinct t3.用户id) as The current number of registered users
from
(
select 用户id,
注册日期,
year(注册日期) as 年份,
week(注册日期,1) as 周数
from Registered user information form
) as t3
left join
(
select year(max(登录日期)) as Most active year,
week(max(登录日期),1) as Active maximum weeks
from 用户登录信息表
) as t4 on 1 = 1
where t3.年份 < t4.Most active year or (t3.年份 = t4.Most active year and t3.周数 <= t4.Active maximum weeks)
) as t5 on 1 = 1;
返回结果为:
【本题考点】
1)Check for user activity metrics“Weekly active user rate”的了解;
2)Test your ability to handle dates,比如week函数的使用;
3)考查对多表联结的了解.
️点击「阅读原文」
免费报名 数据分析训练营
边栏推荐
- 【码蹄集新手村600题】将一个函数定义宏
- mysql delete execution error: You can't specify target table 'doctor_info' for update in FROM clause
- 深入浅出Flask PIN
- 我写了个”不贪吃蛇“小游戏
- 基于DMS的数仓智能运维服务,知多少?
- leetcode-693.交替位二进制数
- 深度学习GPU最全对比,到底谁才是性价比之王?
- Introduction to spark learning - 1
- Small Tools (4) integrated Seata1.5.2 distributed transactions
- 13 and OOM simulation
猜你喜欢
我写了个”不贪吃蛇“小游戏
STM32 GPIO LED and buzzer implementation [Day 4]
Small Tools (4) integrated Seata1.5.2 distributed transactions
Basic knowledge points in js - events
参与便有奖,《新程序员》杂志福利来袭!
DC-DC 2C(40W/30W) JD6606SX2退功率应用
为什么我强烈推荐使用智能化async?
ECCV 2022 | 基于关系查询的时序动作检测方法
To participate in sweepstakes, incoming new programmers magazine welfare!
用友YonSuite与旺店通数据集成对接-技术篇2
随机推荐
leetcode:899. 有序队列【思维题】
ECCV 2022 | Relational Query-Based Temporal Action Detection Methods
语音识别新一轮竞争打响,自然对话会是下一个制高点吗?
【Unity入门计划】基本概念(8)-瓦片地图 TileMap 01
深入浅出Flask PIN
WordPress 5.2.3 更新,升级出现请求超时的解决方法
我在滴滴做开源
字典表(还需要输入2个字)
How to prevent hacking Windows server security Settings
泰山OFFICE技术讲座:文字边框高度研究
泰山OFFICE技术讲座:段落边框的绘制难点在哪里?
DataGrip:非常好用的数据库工具,安装与使用教程,亮点介绍
《安富莱嵌入式周报》第276期:2022.07.25--2022.07.31
如何分析周活跃率?
产品以及研发团队有使用专业的办公软件,如禅道、蓝湖等,他们应该如何使用 Tita 系统?
mysql delete execution error: You can't specify target table 'doctor_info' for update in FROM clause
移动应用出海,你的“网络优化”拖后腿了吗?
如何将二维空间先验注入到ViT中? UMA&港理工&阿里提出SP-ViT,为视觉Transformer学习2D空间先验知识!...
1、实例开启无锁表结构变更以后,在任务编排中通过“单实例SQL”节点进行的结构变更,是优先采用无锁表
CS免杀姿势