当前位置:网站首页>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;边栏推荐
- 数据治理:数据治理管理(第五篇)
- JDBC common interview questions
- Know the future of "edge computing" from the Nobel prize!
- 2022.6.30-----leetcode.1175
- Is it safe for a novice to open a securities account?
- 4GB大文件,如何实时远程传输和共享?
- excel动态图表
- Boot + jsp University Community Management System (with source Download Link)
- Some errors encountered in MySQL data migration
- Beauty of Mathematics - Application of Mathematics
猜你喜欢

Call us special providers of personal cloud services for College Students
Educational administration management system of SSM (free source code)

Continuous breakthrough and steady progress -- Review and Prospect of cross platform development technology of mobile terminal

从MLPerf谈起:如何引领AI加速器的下一波浪潮

基于LabVIEW的计时器

Crossing sect · paipan + Siyuan notes = private notebook

Some errors encountered in MySQL data migration
SSM的教务管理系统(免费源码获取)

He struggled day and night to protect his data

HCM 初学 ( 四 ) - 时间
随机推荐
表格中el-tooltip 实现换行展示
Huluer app help
为什么用葫芦儿派盘取代U盘?
不是你脑子不好用,而是因为你没有找到对的工具
为了保护自己的数据,他奋斗了一天一夜
Crossing pie · pie pan + Mountain duck = local data management
HCM 初学 ( 二 ) - 信息类型
【笔记】电商订单数据分析实战
Codeforces Round #803 (Div. 2)vp
Educational administration management system (free source code)
多表操作-外键级联操作
Chip, an empire built on sand!
Brief description of activation function
Mongodb學習篇:安裝後的入門第一課
Know the future of "edge computing" from the Nobel prize!
What things you didn't understand when you were a child and didn't understand until you grew up?
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
CJC8988带2个立体声耳机驱动器的低功率立体声编解码器
Ssm+mysql second-hand trading website (thesis + source code access link)
Chapitre d'apprentissage mongodb: Introduction à la première leçon après l'installation