当前位置:网站首页>Retention rate of SQL required questions
Retention rate of SQL required questions
2022-07-01 05:47:00 【Begin to change】
Catalog
1、 First find out the earliest login date of each user ( Auxiliary column )
One 、 subject
Query the number of new users per day and their retention rate for the next day and 30 days
Two 、 step
1、 First find out the earliest login date of each user ( Auxiliary column )
SELECT user_id,login_date,MIN(login_date) over (PARTITION by user_id ORDER BY login_date ) as first_login from tb_user_login;2、 Even the table
Associate the table with auxiliary columns with the original table , The associated condition is not only id equal , Another condition is the difference between the login time and the earliest login time
SELECT user_id,login_date,MIN(login_date) over (PARTITION by user_id ORDER BY login_date ) as first_login from tb_user_login)t1
LEFT JOIN tb_user_login as t2
on t1.user_id = t2.user_id and DATEDIFF(t2.login_date,first_login)=1
left JOIN tb_user_login as t3
on t1.user_id = t3.user_id and DATEDIFF(t3.login_date,first_login)=29
GROUP BY first_login,uesr_id;3、 Statistics
COUNT(DISTINCT t1.user_id) as Number of new users ,
COUNT(DISTINCT t2.user_id) /COUNT(DISTINCT t1.user_id) as The next day ,
COUNT(DISTINCT t3.user_id) /COUNT(DISTINCT t1.user_id) as For 30 days 4、 Source code
SELECT user_id,login_date,MIN(login_date) over (PARTITION by user_id ORDER BY login_date ) as first_login from tb_user_login;
# View the date each user logged in
SELECT
first_login,
COUNT(DISTINCT t1.user_id) as Number of new users ,
COUNT(DISTINCT t2.user_id) /COUNT(DISTINCT t1.user_id) as The next day ,
COUNT(DISTINCT t3.user_id) /COUNT(DISTINCT t1.user_id) as For 30 days
from (SELECT user_id,login_date,MIN(login_date) over (PARTITION by user_id ORDER BY login_date ) as first_login from tb_user_login)t1
LEFT JOIN tb_user_login as t2
on t1.user_id = t2.user_id and DATEDIFF(t2.login_date,first_login)=1
left JOIN tb_user_login as t3
on t1.user_id = t3.user_id and DATEDIFF(t3.login_date,first_login)=29
GROUP BY first_login;边栏推荐
- 穿越派·派盘 + Mountain Duck = 数据本地管理
- Summary of common components of applet
- Unity 使用Sqlite
- C language beginner level - realize the minesweeping game
- He struggled day and night to protect his data
- Orcle创建用户+角色
- It's not that you have a bad mind, but that you haven't found the right tool
- Why use huluer pie disk instead of U disk?
- 【考研高数 武忠祥+880版 自用】高数第二章基础阶段思维导图
- Beauty of Mathematics - Application of Mathematics
猜你喜欢

Some errors encountered in MySQL data migration

College community management system based on boot+jsp (with source code download link)

LeetCode 最大矩形,最大正方形系列 84. 85. 221. 1277. 1725. (单调栈,动态规划)

从诺奖知“边缘计算”的未来!

Call us special providers of personal cloud services for College Students

Advanced cross platform application development (III): online resource upgrade / hot update with uni app

激活函数简述

Seven major technical updates that developers should pay most attention to on build 2022

穿越派·派盘 + 思源笔记 = 私人笔记本

基于LabVIEW的计时器
随机推荐
OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)
HCM 初学 ( 二 ) - 信息类型
POL8901 LVDS转MIPI DSI 支持旋转图像处理芯片
轩逸保养手册
导数的左右极限和左右导数的辨析
Qt编写自定义控件-自绘电池
LeetCode 最大矩形,最大正方形系列 84. 85. 221. 1277. 1725. (单调栈,动态规划)
Preliminary level of C language -- selected good questions on niuke.com
Call us special providers of personal cloud services for College Students
Fragment upload and breakpoint resume
【笔记】电商订单数据分析实战
数据治理:数据治理框架(第一篇)
Multi table operation - foreign key cascade operation
Ssm+mysql second-hand trading website (thesis + source code access link)
Leetcode top 100 questions 1 Sum of two numbers
【考研高数 自用】高数第一章基础阶段思维导图
Send you through the data cloud
MySQL converts milliseconds to time string
Know the future of "edge computing" from the Nobel prize!
Brief description of activation function