当前位置:网站首页>What is contemporaneous group analysis? Teach you to use SQL to handle
What is contemporaneous group analysis? Teach you to use SQL to handle
2022-06-29 00:44:00 【Junhong's road of data analysis】
Catalog
One 、 Definition of simultaneous group analysis
Two 、SQL step
1. View the data
2. according to uid 、 Number of aggregated users per month
3. Calculate the difference between month and year ( Days )
4. Calculate the difference between month and year ( Monthly number )
5. perspective ( according to uid 、 The number of users who pay for the first time to see the difference between the months and months )
6. Calculate the retention rate
One 、 Definition of simultaneous group analysis
「 Simultaneous group analysis 」(Cohort Analysis) It's a kind of passing “ Vertically and horizontally ” Combined with the subdivision type analysis of user clustering :
「 Horizontally 」—— Analyze the changes of the same period group as the period goes by
「 Vertically 」—— Analyze the differences between groups at the same stage of the life cycle
「 Contemporaneous group 」 It refers to groups in the same period , It can be a user registered on the same day 、 Users who pay for the first time on the same day .
「 The index change of the cycle 」 It refers to the retention rate of users in a certain period 、 Payment rate and other indicators .
Contemporaneous group analysis consists of three core elements :
「 The first time a customer acts 」: This is the basic point for dividing groups in the same period
「 Time period dimension 」: such as N Daily retention rate 、N Of the daily conversion rate N Japan , Generally, it is +N Japan 、+N month
「 Indicators of change 」: For example, registration conversion rate 、 Payment conversion rate 、 Retention rate and other indicators
Group analysis of the same period gives more detailed measures , Real user behavior can be monitored in real time 、 Measuring user value , And provide support for the optimization and improvement of marketing plan , avoid “ Be averaged ” Vanity data .
Two 、SQL step
I use PostgreSQL Split step to realize the group report of user retention rate in the same period based on the first order date ,「 Each step is reprocessed on the basis of the previous step 」, This is also reflected in the sub query in the code , After sorting out the idea, you will find that it is actually very simple .
The key points are as follows :
Count each user's 「 First order time 」
Calculate the first order time and the actual order time 「 Date difference 」
For the number of paying users 「 To heavy statistics 」
Note the fields 「 Format conversion 」
1. View the data
-- 0. View the data
SELECT * FROM " journal " LIMIT 10;
2. according to uid 、 Number of aggregated users per month
-- 1. according to uid 、 Number of aggregated users per month
SELECT
" journal ".uid,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' ) AS years ,
min(to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )) OVER(PARTITION BY " journal ".uid) AS Month and year of first payment
FROM
" journal "
GROUP BY
" journal ".uid,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )
ORDER BY " journal ".uid;
3. Calculate the difference between month and year ( Days )
-- 2. Calculate the difference between month and year ( Days )
SELECT *,to_date(t. years ,'YYYY-MM') - to_date(t. Month and year of first payment ,'YYYY-MM') AS Days difference
FROM (SELECT
" journal ".uid,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' ) AS years ,
min(to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )) OVER(PARTITION BY " journal ".uid) AS Month and year of first payment
FROM
" journal "
GROUP BY
" journal ".uid,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )
ORDER BY " journal ".uid) AS t;
4. Calculate the difference between month and year ( Monthly number )
-- 3. Calculate the difference between month and year ( Monthly number )
SELECT t.*,
(case when t." Days difference " <= 30 then ' First month '
when t." Days difference " <= 60 then '+1 month '
when t." Days difference " <= 90 then '+2 month '
when t." Days difference " <= 120 then '+3 month '
when t." Days difference " <= 150 then '+4 month '
else NULL
END) AS Monthly difference
FROM (SELECT *,to_date(t. years ,'YYYY-MM') - to_date(t. Month and year of first payment ,'YYYY-MM') AS Days difference
FROM (SELECT
" journal ".uid,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' ) AS years ,
min(to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )) OVER(PARTITION BY " journal ".uid) AS Month and year of first payment
FROM
" journal "
GROUP BY
" journal ".uid,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )
ORDER BY " journal ".uid) AS t) AS t;
5. perspective ( according to uid 、 The number of users who pay for the first time to see the difference between the months and months )
-- 4. perspective ( according to uid 、 The number of users who pay for the first time to see the difference between the months and months )
SELECT t. Month and year of first payment ,
count(distinct case when t. Month month difference = 0 then t.uid else NULL end) AS First month ,
count(distinct case when t. Month month difference = 1 then t.uid else NULL end) AS "+1 month ",
count(distinct case when t. Month month difference = 2 then t.uid else NULL end) AS "+2 month ",
count(distinct case when t. Month month difference = 3 then t.uid else NULL end) AS "+3 month ",
count(distinct case when t. Month month difference = 4 then t.uid else NULL end) AS "+4 month "
FROM (SELECT * FROM (SELECT *,round((to_date(t. years ,'YYYY-MM') - to_date(t. Month and year of first payment ,'YYYY-MM')) / 30,0) AS Month month difference
FROM (SELECT
" journal ".uid:: text,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' ) AS years ,
min(to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )) OVER(PARTITION BY " journal ".uid) AS Month and year of first payment
FROM
" journal "
GROUP BY
" journal ".uid,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )
ORDER BY " journal ".uid) AS t) AS t) AS t
GROUP BY t. Month and year of first payment ;
6. Calculate the retention rate
-- 5. Calculate the retention rate
SELECT t. Month and year of first payment ,t. First month ,
round((t."+1 month "::numeric / t. First month ::numeric) * 100,2)::text || '%' AS "1 After month ",
round((t."+2 month "::numeric / t. First month ::numeric) * 100,2)::text || '%' AS "2 After month ",
round((t."+3 month "::numeric / t. First month ::numeric) * 100,2)::text || '%' AS "3 After month ",
round((t."+4 month "::numeric / t. First month ::numeric) * 100,2)::text || '%' AS "4 After month "
FROM(SELECT t. Month and year of first payment ,
count(distinct case when t. Month month difference = 0 then t.uid else NULL end) AS First month ,
count(distinct case when t. Month month difference = 1 then t.uid else NULL end) AS "+1 month ",
count(distinct case when t. Month month difference = 2 then t.uid else NULL end) AS "+2 month ",
count(distinct case when t. Month month difference = 3 then t.uid else NULL end) AS "+3 month ",
count(distinct case when t. Month month difference = 4 then t.uid else NULL end) AS "+4 month "
FROM (SELECT * FROM (SELECT *,round((to_date(t. years ,'YYYY-MM') - to_date(t. Month and year of first payment ,'YYYY-MM')) / 30,0) AS Month month difference
FROM (SELECT
" journal ".uid:: text,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' ) AS years ,
min(to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )) OVER(PARTITION BY " journal ".uid) AS Month and year of first payment
FROM
" journal "
GROUP BY
" journal ".uid,
to_char( to_date( " journal "." date ", 'YYYY-MM' ), 'YYYY-MM' )
ORDER BY " journal ".uid) AS t) AS t) AS t
GROUP BY t. Month and year of first payment ) AS t;
- END -
contrast Excel The cumulative sales of the series of books reached 15w book , Make it easy for you to master data analysis skills , You can click on the link below to learn about purchasing :边栏推荐
- 矩 阵 压 缩
- 10. Yolo series
- Program environment and pretreatment
- Comics | goodbye, postman! One stop collaboration makes apipost more fragrant!
- JVM工作原理介绍
- Go1.18 new feature: discard strings Title Method, a new pit!
- 机器视觉系统的配件及工作过程
- [image detection] recognition of the front and back of a coin based on texture features with matlab code attached
- Document management.
- Redis common command manual
猜你喜欢

Reprint: VTK notes - clipping and segmentation - irregular closed loop clipping -vtkselectpolydata class (black mountain old demon)

Redis常用命令手册

运营级智慧校园系统源码 智慧校园小程序源码+电子班牌+人脸识别系统

Go1.18 new feature: discard strings Title Method, a new pit!

Report on the convenient bee Lantern Festival: the first peak sales of pasta products this year; prefabricated wine dumplings became the winners

Xuetong denies that the theft of QQ number is related to it: it has been reported; IPhone 14 is ready for mass production: four models are launched simultaneously; Simple and elegant software has long

使用.Net驱动Jetson Nano的OLED显示屏

架构实战营|模块5

How to calculate the income tax of foreign-funded enterprises

Baidu online disk login verification prompt: unable to access this page, or the QR code display fails, the pop-up window shows: unable to access this page, ensure the web address....
随机推荐
[MCU club] design of GSM version of range hood based on MCU [physical design]
Jbridge bridging frame technology for AI computing power landing
矩 阵 压 缩
Redis是什么
架构实战营|模块5
Is it safe to open an account on the flush
If you can play these four we media operation tools, the sideline income of 6000+ is very easy
Document management.
Basic use of Chrome browser
畢業三年的25歲碼農總結
学习通否认 QQ 号被盗与其有关:已报案;iPhone 14 量产工作就绪:四款齐发;简洁优雅的软件早已是明日黄花|极客头条
Remove HTML tags from Oracle
Résumé de Manon, 25 ans, diplômé en trois ans
Is l1-031 too fat (10 points)
Blazor University (34)表单 —— 获得表单状态
Report on the convenient bee Lantern Festival: the first peak sales of pasta products this year; prefabricated wine dumplings became the winners
利用verilogA模块采样
Notes on the infrastructure of large websites
[image detection] recognition of the front and back of a coin based on texture features with matlab code attached
Comparison between winding process and lamination process