当前位置:网站首页>SQL164 2021年11月每天新用户的次日留存率
SQL164 2021年11月每天新用户的次日留存率
2022-07-21 08:09:00 【Yuki_1999】
#每个用户首次活跃的日期,表1
select uid,date(min(in_time))
from tb_user_log
group by uid
#每个用户全部活跃的日期,表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
#查看当日、次日用户的活跃情况,次日uid为空说明次日没有留存
#返回四列:当日日期,uid,次日日期,uid
#表1左连接表2,条件是日期相差1天
1、timestampdiff(单位,开始时间,结束时间)
单位:sencond,minute,hour,day,week,month,year
2、from...join...on+条件
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
#计算次留
1、round(a,3):a保留三位小数
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%" #限制时间范围
group by a.dt
边栏推荐
- Configuration and use of kaptcha verification code
- 记一次远程Debug调试Minecraft服务器插件经历
- EasyExcel实现文件上传-批量插入 文件下载
- 【集训DAY8】【Luogu_P6335】Staza【Tarjan】
- 【集训DAY10】Silly【模拟】【贪心】
- [Yugong series] go teaching course in July 2022 014 arithmetic operators of operators
- Stream流中的Map与flatMap的区别
- 动态规划背包问题——01背包
- Unity 之UGUI Text组件坚排显示(改进)
- 【集训DAY8】Interesting Number 【数位DP】
猜你喜欢
C language classic 100 questions (1-10 questions) (including answers)
Advantages and disadvantages of Tongniu computer room project
Payment system - reconciliation system
Using completable future to implement asynchronous callback
近红外染料CY7.5标记PNA多肽实验步骤CY7.5-PNA|188Re标记反基因肽核酸(AGPNA)
转载:CAN总线终端电阻
weirdo The interview topics include toilet habits, eating time and sleeping time
Aruba学习笔记03-Web UI --Monitoring面板介绍
linux服务器安装了图形界面,但是在安装数据库时显示初始化图形界面失败
动态递归之严格位置依赖优化
随机推荐
XMLDecoder解析流程分析
[wechat applet] solve the problem that the code upload exceeds the size limit and the applet is subcontracted
屏幕共享软件--Deskreen
Problems and principle analysis of audio AGC
JS regular case
Visualization: you must know these ten data visualization tool software platforms
【集训DAY8】Tent【数学】【DP】
点击按钮,丝滑的返回顶部
群晖7.1.0万兆网络实测
1. Source code analysis of Nacos configuration center Hello World
如何修改MySQL监听IP地址
氟尼辛肽核酸寡聚体复合物|规活性基团Alkyne炔烃,SH Thiol炔基修饰肽核酸
小程序 奇葩BUG 更新~
Deploy server
软件测试面试小技巧 | 如果你没收到offer我倒立洗头
【集训DAY9】Light Tank【动态规划】
一文深入浅出理解国产开源木兰许可系列协议
First knowledge of loop and branch statements in C language
新知识经济时代,谁在生产知识?
动态规矩-数组压缩优化