当前位置:网站首页>Sql164 next day retention rate of new users per day in November 2021
Sql164 next day retention rate of new users per day in November 2021
2022-07-24 20:05:00 【Yuki_ one thousand nine hundred and ninety-nine】
# The date each user was first active , surface 1
select uid,date(min(in_time))
from tb_user_log
group by uid
# The date each user is active , surface 2
select uid,date(in_time)as dt
from tb_user_log
union
select uid,date(out_time)as dt
from tb_user_log
order by uid
# Check the current day 、 The activity of users the next day , The next day uid If it is blank, it means that it is not retained the next day
# Return four columns : Date of the day ,uid, The next day ,uid
# surface 1 Left link table 2, The condition is that the date is different 1 God
1、timestampdiff( Company , Starting time , End time )
Company :sencond,minute,hour,day,week,month,year
2、from...join...on+ Conditions
select *
from
(select uid,date(min(in_time))as dt
from tb_user_log
group by uid)as a
left join
(select uid,date(in_time)as dt
from tb_user_log
union
select uid,date(out_time)as dt
from tb_user_log
order by uid)as b
on a.uid=b.uid
and timestampdiff(day,a.dt,b.dt)=1
# Calculate secondary retention
1、round(a,3):a Keep three decimal places
select a.dt
,round(count(b.uid)/count(a.uid),2)as uv_left_rate
from
(select uid,date(min(in_time))as dt
from tb_user_log
group by uid)as a
left join
(select uid,date(in_time)as dt
from tb_user_log
union
select uid,date(out_time)as dt
from tb_user_log
order by uid)as b
on a.uid=b.uid
and timestampdiff(day,a.dt,b.dt)=1
where a.dt like"2021-11%" # Limit the time range
group by a.dt
边栏推荐
- Browser local storage webstroage
- Sword finger offer 48. the longest substring without repeated characters
- Lights of thousands of families in the year of xinchou
- Basic idea of regularization
- [untitled]
- [trial experience of Yuxin micro Wiota ad hoc network protocol development kit] RT thread BSP Software package production
- Stop using UUID indiscriminately. Have you tested the performance gap between self incrementing ID and UUID?
- Todolist case
- Modbus communication protocol specification (Chinese) sharing
- Know typescript
猜你喜欢

Analysis and Simulation of strlen function

C# 窗体应用TreeView控件使用

聊下自己转型测试开发的历程

147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用

Alibaba cloud technology expert Yang Zeqiang: building observable capabilities on elastic computing cloud

从服务器批量下载文件到本地

Todolist case

Istio二之流量劫持过程

Flink Window&Time 原理

Unity2d~ game practice of decrypting Zhou mu (completed in three days)
随机推荐
MySQL advanced 2
Introduction and advanced tutorial of Albert duilib
Mysql8.0 learning record 19 - Page segments and tablespaces
About the largeheap attribute
Usage and introduction of MySQL binlog
Cmake series tutorial 2 HelloWorld
Sword finger offer 46. translate numbers into strings
Sword finger offer 50. the first character that appears only once
day 1
【德味】安全:如何为行人提供更多保护
Mysql8.0 learning record 20 - trigger
原反补及大小端
Mass modify attribute values in objects in JS
YouTube "label products" pilot project launched
Lights of thousands of families in the year of xinchou
Software core data protection solution
拿捏C指针
Day 10 (inheritance, rewriting and use of super)
Review the code implementation of memcpy function
Sword finger offer 42. maximum sum of continuous subarrays