当前位置:网站首页>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;边栏推荐
- 这才是大学生必备软件 | 知识管理
- 【笔记】电商订单数据分析实战
- Learn the customization and testing of fpga---ram IP from the bottom structure
- MySQL converts milliseconds to time string
- Preliminary level of C language -- selected good questions on niuke.com
- Advanced cross platform application development (III): online resource upgrade / hot update with uni app
- JDBC常见面试题
- Idea start view project port
- 2022.6.30-----leetcode. one thousand one hundred and seventy-five
- Data governance: data governance framework (Part I)
猜你喜欢

boot+jsp的高校社团管理系统(附源码下载链接)

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

Advanced drawing skills of Excel lecture 100 (1) - use Gantt chart to show the progress of the project

论文学习记录随笔 多标签之LIFT

Leetcode top 100 question 2 Add two numbers

教务管理系统(免费源码获取)

Debug details under pycharm
![[QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved](/img/30/c802ae9b65601832bf52e760e9962d.png)
[QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved

基于LabVIEW的计时器

HCM 初学 ( 三 ) - 快速输入PA70、PA71 浏览员工信息PA10
随机推荐
Qt编写自定义控件-自绘电池
This is the necessary software for college students 𞓜 knowledge management
【笔记】电商订单数据分析实战
这才是大学生必备软件 | 知识管理
boot+jsp的高校社团管理系统(附源码下载链接)
千万不要把笔记视频乱放!
多表操作-外键级联操作
POL8901 LVDS转MIPI DSI 支持旋转图像处理芯片
运行时候的导包搜索路径虽然pycharm中标红但不影响程序的执行
Wild melon or split melon?
【QT】qt加减乘除之后,保留小数点后两位
不是你脑子不好用,而是因为你没有找到对的工具
Educational administration management system of SSM (free source code)
Trust guessing numbers game
Continuous breakthrough and steady progress -- Review and Prospect of cross platform development technology of mobile terminal
How to transmit and share 4GB large files remotely in real time?
Idea start view project port
HDU - 1024 Max Sum Plus Plus(DP)
excel初级应用案例——杜邦分析仪
【知识点总结】卡方分布,t分布,F分布