当前位置:网站首页>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;边栏推荐
- bat操作ftp上传下载命令
- Xuanyi maintenance manual
- ssm+mysql二手交易网站(论文+源码获取链接)
- 为什么用葫芦儿派盘取代U盘?
- 【问题思考总结】为什么寄存器清零是在用户态进行的?
- Mongodb learning chapter: introduction after installation lesson 1
- He struggled day and night to protect his data
- 4GB大文件,如何实时远程传输和共享?
- [excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
- Ssm+mysql second-hand trading website (thesis + source code access link)
猜你喜欢
随机推荐
穿越派 你的数据云行
Wild melon or split melon?
健康照明中应用的LED照明灯
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
Qt编译时,出现 first defined here,原因及解决方法
轩逸保养手册
Seven major technical updates that developers should pay most attention to on build 2022
Learn the customization and testing of fpga---ram IP from the bottom structure
Send you through the data cloud
关于一道01背包问题的·拓展题的思考
Orcle创建用户+角色
Simple implementation of database connection pool
【QT】qt加减乘除之后,保留小数点后两位
Common solutions for mobile terminals
【考研高数 自用】高数第一章基础阶段思维导图
Ucosiii --- engineering transplantation
Deeply understand the underlying implementation principle of countdownlatch in concurrent programming
Unity 使用Sqlite
Crossing sect · paipan + Siyuan notes = private notebook
Bat operation FTP upload and download command







![[medical segmentation] u2net](/img/b3/b1d188216310fe1217e360ac56af3b.jpg)

