当前位置:网站首页>Real MySQL interview questions (XXVII) -- Classification of users by RFM analysis method
Real MySQL interview questions (XXVII) -- Classification of users by RFM analysis method
2022-06-23 05:48:00 【Socialphobia_ FOGO】
RFM Classification of users by analytical method
Here is 2020 year 1 User behavior record of an e-commerce platform in January :
The business problem : The store found that , User operation is too extensive , Failed to achieve user classified operation . The boss wants to carry out targeted marketing for different users next month , Reduce costs and increase revenue , The effect of refined operation . What do I do ?
Involving user classification , It can be used RFM Analysis method .
One . What is? RFM Analysis method ?
RFM The analysis method is based on the user's last consumption interval (Recency)、 Consumption frequency (Frequency)、 Consumption amount (Monetary) To score users , Then users are divided into different types according to scores , Then use different operation strategies for different users , So as to realize auxiliary precision operation .
RFM The analysis method divides users into the following 8 class :

Two . How to use SQL Realization RFM Analysis method ?
1. Define indicators R、F、M
Set the... In the indicator definition “ A span “ Defined as 1 month (31 God ).
The last consumption interval : The user's last consumption is now (1 month 31 Japan ) How long has it been .
Consumption frequency (F): Users for a period of time (1 month ) How many times did you spend .
Consumption amount (M): Users for a period of time (1 month ) Amount of consumption , Corresponds to “ Consumption amount “.

WITH temp1 AS (
SELECT *
FROM User behavior record
WHERE User behavior type =' Buy '
),
temp2 AS (
SELECT The user id ,MAX( User active date ) AS Last shopping date
FROM temp1
GROUP BY The user id
),
temp3 AS (-- Find out the user number and the latest consumption time interval R
SELECT The user id ,DATEDIFF('2020-01-31',temp2. Last shopping date ) AS The last consumption interval R
FROM temp2
),
temp4 AS (-- Find out the user number and consumption frequency F
SELECT The user id ,COUNT(*) AS Consumption frequency F
FROM temp1
WHERE DATEDIFF('2020-01-31', User active date )<=30
GROUP BY The user id
),
temp5 AS (-- Find out the user number and consumption amount M
SELECT The user id ,SUM( Consumption amount ) AS Total consumption amount M
FROM temp1
WHERE DATEDIFF('2020-01-31', User active date )<=30
GROUP BY The user id
),
temp6 AS(-- Summarize user numbers and RFM
SELECT temp3. The user id , The last consumption interval R AS R, Consumption frequency F AS F, Total consumption amount M AS M FROM temp3
JOIN temp4 ON temp3. The user id =temp4. The user id
JOIN temp5 ON temp3. The user id =temp5. The user id
),
temp7 AS (-- For each user RFM Scoring
SELECT *,
CASE WHEN R>15 THEN 1
WHEN R>10 AND R<=15 THEN 2
WHEN R>5 AND R<=10 THEN 3
WHEN R>3 AND R<=5 THEN 4
ELSE 5 END AS R branch ,
CASE WHEN F<=1 THEN 1
WHEN F>1 AND F<=3 THEN 2
WHEN F>3 AND F<=5 THEN 3
WHEN F>5 AND F<=7 THEN 4
ELSE 5 END AS F branch ,
CASE WHEN M<=500 THEN 1
WHEN M>500 AND M<=1000 THEN 2
WHEN M>1000 AND M<=1500 THEN 3
WHEN M>1500 AND M<=2000 THEN 4
ELSE 5 END AS M branch
FROM temp6
),
temp8 AS (-- Find out RFM The average of the scores
SELECT AVG(R branch ) AS R Average score ,AVG(F branch ) AS F Average score ,AVG(M branch ) AS M Average score
FROM temp7
),
temp9 AS (-- Put each user's RFM Compare with the corresponding average
SELECT temp7. The user id ,
CASE WHEN R branch >R Average score THEN ' high ' ELSE ' low ' END AS R classification ,
CASE WHEN F branch >F Average score THEN ' high ' ELSE ' low ' END AS F classification ,
CASE WHEN M branch >M Average score THEN ' high ' ELSE ' low ' END AS M classification
FROM temp7
JOIN temp8
),
temp10 AS (-- Match user categories
SELECT The user id ,
CASE WHEN R classification =' high ' AND F classification =' high ' AND M classification =' high ' THEN ' Important value users '
WHEN R classification =' high ' AND F classification =' low ' AND M classification =' high ' THEN ' Important value users '
WHEN R classification =' low ' AND F classification =' high ' AND M classification =' high ' THEN ' It's important to keep users '
WHEN R classification =' low ' AND F classification =' low ' AND M classification =' high ' THEN ' Important to keep users '
WHEN R classification =' high ' AND F classification =' high ' AND M classification =' low ' THEN ' General value users '
WHEN R classification =' high ' AND F classification =' low ' AND M classification =' low ' THEN ' General development users '
WHEN R classification =' low ' AND F classification =' high ' AND M classification =' low ' THEN ' General user retention '
WHEN R classification =' low ' AND F classification =' low ' AND M classification =' low ' THEN ' Generally retain users '
END AS The user classification
FROM temp9
)
SELECT * FROM temp10
give the result as follows :
According to the analysis , You can carry out fine operation for users ~
边栏推荐
- Wechat applet: an artifact for calculating the full amount of orders
- 高等数学(第七版)同济大学 习题1-9 个人解答
- Yingjixin launched 4 series of lithium batteries 100W mobile power supply voltage rise and fall scheme SOC chip ip5389
- Huawei's software and hardware ecosystem has taken shape, fundamentally changing the leading position of the United States in the software and hardware system
- Heimdall Database Proxy横向扩展提高20倍
- 低成本5W无线充电器方案FS68001B简便充电芯片
- What is the magic of digital collections? Which reliable teams are currently developing
- MySQL面试真题(二十四)——行列互换
- fastjson中的@JSONField注解
- PAT 乙等 1021 个位数统计
猜你喜欢

制造业数字化转型存在问题及原因分析

数字藏品赋能实体产业释放了哪些利好?

C primer plus learning notes - 2. Constant and formatted IO (input / output)

Adnroid activity截屏 保存显示到相册 View显示图片 动画消失

MySQL面试真题(二十六)——滴滴2020年笔试题
![[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code](/img/e2/24eb2a60e3dc603b3ec4bfefd0b8e5.png)
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code

51万奖池邀你参战——第二届阿里云ECS CloudBuild开发者大赛来袭

Heimdall Database Proxy横向扩展提高20倍

True question of MySQL interview (29) -- case - finding favorite movies

The digital collection market has just begun
随机推荐
@jsonfield annotation in fastjson
PAT 乙等 1024 科学记数法 C语言
FS4059A与FS5080E充电芯片的区别
Wechat applet; AI intelligent dubbing assistant
Arctime makes Chinese and English subtitle video
Kotlin android简单Activity跳转、handler和thread简单配合使用
Opportunities and challenges of digital collections from the perspective of technology development team
SIFT feature point extraction
PAT 乙等 1018 C语言
工作积累-判断GPS是否打开
ORB_ Slam2 operation
MySQL面试真题(二十五)——常见的分组比较场景
知识点滴 - 折叠锻打和大马士革钢
Ansible 使用普通用户管理被控端
PAT 乙等 1009 C语言
常用的无线充发射IC芯片
The author believes that the so-called industrial Internet is a process of deep integration of industry and the Internet
Yingjixin ip5566 with type-C port 3A charging and discharging fast charging mobile power supply 5W wireless charging in one SOC
编址和编址单位
HierarchyViewer工具找不到 HierarchyViewer位置