当前位置:网站首页>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;边栏推荐
- 葫芦儿 APP 使用帮助
- Data governance: data governance framework (Part I)
- Geoffrey Hinton:我的五十年深度学习生涯与研究心法
- 2022.6.30-----leetcode. one thousand one hundred and seventy-five
- Boot + jsp University Community Management System (with source Download Link)
- 千万不要把笔记视频乱放!
- OpenGL ES: (4) EGL API详解 (转)
- Trust guessing numbers game
- Leetcode top 100 questions 1 Sum of two numbers
- Crossing sect · paipan + Siyuan notes = private notebook
猜你喜欢

基于LabVIEW的计时器

scope 数据导出mat

为了保护自己的数据,他奋斗了一天一夜

Learn the customization and testing of fpga---ram IP from the bottom structure

OpenGL ES: (3) EGL、EGL绘图的基本步骤、EGLSurface、ANativeWindow

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

Scope data export mat

扩展点系列之SmartInstantiationAwareBeanPostProcessor确定执行哪一个构造方法 - 第432篇

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

Continue to learn MySQL
随机推荐
libpng12.so.0: cannot open shared object file: No such file or directory 亲测有效
Chapitre d'apprentissage mongodb: Introduction à la première leçon après l'installation
这才是大学生必备软件 | 知识管理
Code shoe set - mt3114 · interesting balance - explain it with examples
表格中el-tooltip 实现换行展示
2022 the 8th China International "Internet +" college student innovation and entrepreneurship competition industry proposition track is open for registration!
穿越派·派盘 + Mountain Duck = 数据本地管理
Some errors encountered in MySQL data migration
我从技术到产品经理的几点体会
Huluer app help
JDBC common interview questions
【QT】qt加减乘除之后,保留小数点后两位
Continuous breakthrough and steady progress -- Review and Prospect of cross platform development technology of mobile terminal
Daily code 300 lines learning notes day 11
Deeply understand the underlying implementation principle of countdownlatch in concurrent programming
数据库连接池的简单实现
College community management system based on boot+jsp (with source code download link)
Simple implementation of database connection pool
Data governance: metadata management implementation (Part IV)
Looking for high school student developers with similar interests