当前位置:网站首页>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)考查对多表联结的了解.
️点击「阅读原文」
免费报名 数据分析训练营
边栏推荐
- CS免杀姿势
- Detailed explanation of ReentrantReadWriteLock
- Some optional strategies and usage scenarios for PWA application Service Worker caching
- Small Tools (4) integrated Seata1.5.2 distributed transactions
- 高可用版 主数据库数据结构改变 备数据库会自动改变吗
- ReentrantLock详解
- 参与便有奖,《新程序员》杂志福利来袭!
- [Unity Getting Started Plan] Basic Concepts (8) - Tile Map TileMap 01
- AI也有健忘症?英国41岁教授专访:解决灾难性遗忘
- 不可忽略!户外LED显示屏的特点及优势
猜你喜欢
随机推荐
JD6606SP5_JD6606SSP_JD6606SASP_JD6621W7百盛新纪元授权代理商
Go Go 简单的很,标准库之 fmt 包的一键入门
【码蹄集新手村600题】将一个函数定义宏
Some optional strategies and usage scenarios for PWA application Service Worker caching
WordPress 5.2.3 更新,升级出现请求超时的解决方法
13、OOM模拟
Difference and performance comparison between HAL and LL library of STM32
mysql delete 执行报错:You can‘t specify target table ‘doctor_info‘ for update in FROM clause
一个文件管理系统的软硬件配置清单
新一代网状网协议T-Mesh无线通信技术优势介绍
Yuan xiaolin: Volvo focus on travel security, and put it perfectly
开源一夏 | 阿里云物联网平台之极速体验
[微信小程序开发者工具] × #initialize
Small Tools(4) 整合Seata1.5.2分布式事务
爬虫注意
unity用代码生成LightProbeGroup
高压直流输电(HVDC)的最优潮流(OPF)(Matlab代码实现)
DataGrip:非常好用的数据库工具,安装与使用教程,亮点介绍
如何选择合适的损失函数,请看......
2021年数据泄露成本报告解读