当前位置:网站首页>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)考查对多表联结的了解.


️点击「阅读原文」
免费报名 数据分析训练营
边栏推荐
- devops-2:Jenkins的使用及Pipeline语法讲解
- 技术干货|如何将 Pulsar 数据快速且无缝接入 Apache Doris
- 爬虫注意
- 高压直流输电(HVDC)的最优潮流(OPF)(Matlab代码实现)
- 30W 2C(JD6606S + FP6652X2)BOM
- Leetcode76. 最小覆盖子串
- Interpretation of the 2021 Cost of Data Breach Report
- ECCV 2022 | 基于关系查询的时序动作检测方法
- JD6606SP5_JD6606SSP_JD6606SASP_JD6621W7百盛新纪元授权代理商
- unity用代码生成LightProbeGroup
猜你喜欢

如何选择合适的损失函数,请看......

CS免杀姿势

Research on power flow in DC microgrid based on Newton's method (Matlab code implementation)

想进阿里?先来搞懂一下分布式事务

AI+BI+Visualization, Deep Analysis of Sugar BI Architecture

TCP 可靠吗?为什么?

袁小林:沃尔沃专注于出行的安全感,并且把它做到极致

MATLAB gcf图窗保存图像,黑色背景/透明背景

JD6606SP5_JD6606SSP_JD6606SASP_JD6621W7百盛新纪元授权代理商

js中的基础知识点 —— 事件
随机推荐
Some optional strategies and usage scenarios for PWA application Service Worker caching
【Unity入门计划】基本概念(8)-瓦片地图 TileMap 02
JS基础--判断
红蓝对抗经验分享:CS免杀姿势
【Unity入门计划】基本概念(6)-精灵渲染器 Sprite Renderer
实时渲染流程操作复杂吗,如何实现?
《安富莱嵌入式周报》第276期:2022.07.25--2022.07.31
移动应用出海,你的“网络优化”拖后腿了吗?
ReentrantReadWriteLock详解
How much do you know about the intelligent operation and maintenance service of data warehouse based on DMS?
STM32的HAL和LL库区别和性能对比
神经网络,凉了?
[Unity Getting Started Plan] Basic Concepts (8) - Tile Map TileMap 02
JS basics--judgment
深入浅出Flask PIN
托尔斯泰:生活中只有两种不幸
leetcode: 899. Ordered Queue [Thinking Question]
出海季,互联网出海锦囊之本地化
劲爆!协程终于来了!线程即将是过去式
Neural networks, cool?