数据库
首页 > 数据库> > 基于MySQL的电商⽤户、商品、平台价值分析

基于MySQL的电商⽤户、商品、平台价值分析

作者:互联网

文章目录

1.项⽬背景

随着电商⾏业近⼏年的迅猛发展,电⼦商务从早些年的粗放式经营,逐步转化为精细化运营。随着平台数据量的不断积累,通过数据分析挖掘消费者的潜在需求,消费偏好成为平台运营过程中的重要环节。本项⽬基于某电商平台⽤户⾏为数据,在MySQL关系型数据库,探索⽤户⾏为规律,寻找⾼价值⽤户;分析商品特征,寻找⾼贡献商品;分析产品功能,优化产品路径。

2.分析流程

在这里插入图片描述
使用“人货场”拆解方式建立指标体系

3.确认问题

本次分析的⽬的是想通过对⽤户⾏为数据进⾏分析,为以下问题提供解释和改进建议:
1)基于漏⽃模型的⽤户购买流程各环节分析指标,确定各个环节的转换率,便于找到需要改进的环节;
2)商品分析:找出热销商品,研究热销商品特点;
3)基于RFM模型找出核⼼付费⽤户群,对这部分⽤户进⾏精准营销。

4.数据说明

在这里插入图片描述

5.指标体系建设

5.1用户指标体系

根据“人货场”体系建立基础指标(UV/PV/留存率)和RFM模型分析。

  1. 重要高价值客户:指最近⼀次消费较近且消费频率较⾼的客户
  2. 重要唤回客户:指最近⼀次消费较远且消费频率较⾼的客户
  3. 重要深耕客户:指最近⼀次消费较近且消费频率较低的客户
  4. 重要挽留客户:指最近⼀次消费较远且消费频率较低的客户

5.2 商品指标体系

商品指标主要有:

5.3 平台指标体系

⾏为指标:
点击次数 收藏次数 加购物⻋次数 购买次数 购买转化(该平台当⽇的所有⽤户中有购买转化的⽤户⽐)

6. 结论

6.1 ⽤户分析

UV异常分析:每⽇ UV数据中,明显异常点为双⼗⼆活动造成,该影响为已知影响。

在这里插入图片描述

对于UV周环⽐的分析:⽇常周环⽐数据⼤多⼤于0,说明⽤户程⼀定上升趋势,其中如11⽉ 26⽇、 12⽉2⽇、 12⽉ 7⽇等的数据为下降数据,需要结合其他数据做进⼀步的下降原因分析。双⼗⼆活动后⽤户周环⽐会相应下降,为正常原因。

在这里插入图片描述

猜测可能的问题有

6.2 ⽤户精细化运营

通过RFM模型中的⽤户最近⼀次购买时间、⽤户消费频次分析,分拆得到以下重要⽤户。可以在后续精细化运营场景中直接使⽤细分⽤户,做差异化运营:

在这里插入图片描述
在这里插入图片描述

6.3 商品分析

热销商品品类如下所示。
其中’5027‘、 ’5399‘品类购买转化率较其余商品品类偏低,需要结合更多数据做进⼀步解读。

在这里插入图片描述

可能的原因:品类⾃有特性导致⽤户购买较低,⽐如⾮必需品、奢侈品等等。

6.4 产品功能路径分析

以下为主要购买路径。可以发现⽤户多以直接购买为主;添加购物⻋的购买在主要购买路径中数量较少。后续的产品加购功能和产品收藏功能还需要结合更多数据做改进⽅案。
在这里插入图片描述

附录代码

-- 表处理
create table o_retailers_trade_user
(
user_id int (9),
item_id int (9),
behavior_type int (1),
user_geohash varchar (14),
item_category int (5),
time varchar (13)
);

-- 增加新列date_time、 dates,
UPDATE o_retailers_trade_user 
SET dates = date( date_time );
DESC o_retailers_trade_user;

ALTER TABLE o_retailers_trade_user ADD COLUMN date_time datetime NULL;
UPDATE o_retailers_trade_user 
SET date_time = str_to_date( time, '%Y-%m-%d %H' );-- %H可以表示0-23;⽽%h表示0-12

ALTER TABLE o_retailers_trade_user ADD COLUMN dates CHAR ( 10 ) NULL;
UPDATE o_retailers_trade_user 
SET dates = date( date_time );
DESC o_retailers_trade_user;
	
	
-- 重复值处理:创建新表a,并插入5W条数据。
create table temp_trade like o_retailers_trade_user;
insert into temp_trade select distinct * from o_retailers_trade_user limit 50000;	

-- 用户指标
-- 基础指标:uv、 pv、留存率(按日)统计
SELECT
	dates,
	count( DISTINCT user_id ) AS 'uv',
	count( IF ( behavior_type = 1, user_id, NULL ) ) AS 'pv',
	count( IF ( behavior_type = 1, user_id, NULL ) ) / count( DISTINCT user_id ) AS 'pv/uv' 
FROM
	temp_trade 
GROUP BY
	dates;
	
	
-- 用户留存
WITH temp_table_trades AS 
(
	SELECT
		a.dates,
		count( DISTINCT b.user_id ) AS device_v,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 0, b.user_id, NULL ) ) AS device_v_remain0,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 1, b.user_id, NULL ) ) AS device_v_remain1,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 2, b.user_id, NULL ) ) AS device_v_remain2,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 3, b.user_id, NULL ) ) AS device_v_remain3,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 4, b.user_id, NULL ) ) AS device_v_remain4,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 5, b.user_id, NULL ) ) AS device_v_remain5,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 6, b.user_id, NULL ) ) AS device_v_remain6,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 7, b.user_id, NULL ) ) AS device_v_remain7,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 15, b.user_id, NULL ) ) AS device_v_remain15,
		count( DISTINCT IF ( datediff( b.dates, a.dates ) = 30, b.user_id, NULL ) ) AS device_v_remain30 
	FROM
		( SELECT user_id, dates FROM temp_trade GROUP BY user_id, dates ) a
	LEFT JOIN 
		( SELECT dates, user_id FROM temp_trade GROUP BY dates, user_id ) b 
	ON a.user_id = b.user_id 
	WHERE
		b.dates >= a.dates 
	GROUP BY
		a.dates 
)
SELECT
	dates,
	device_v_remain0,
	concat( cast( ( device_v_remain1 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_1%',
	concat( cast( ( device_v_remain2 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_2%',
	concat( cast( ( device_v_remain3 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_3%',
	concat( cast( ( device_v_remain4 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_4%',
	concat( cast( ( device_v_remain5 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_5%',
	concat( cast( ( device_v_remain6 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_6%',
	concat( cast( ( device_v_remain7 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_7%',
	concat( cast( ( device_v_remain15 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_15%',
	concat( cast( ( device_v_remain30 / device_v_remain0 ) * 100 AS DECIMAL ( 18, 2 ) ), '%' ) AS 'day_30%' 
FROM
	temp_table_trades;


-- RFM模型
-- 1.建立r视图,将近期购买时间提取到R临时表中

DROP VIEW IF EXISTS user_recency;
	
CREATE VIEW user_recency AS 
SELECT
	user_id,
	max( dates ) AS rec_buy_time 
FROM
	temp_trade 
WHERE
	behavior_type = '2' 
GROUP BY
	user_id 
ORDER BY
	rec_buy_time DESC;
	
	
-- 2.建立R等级划分视图:将客户近期购买时间进行等级划分,越接近2019-12-18号R越大;

DROP VIEW IF EXISTS r_clevel;

CREATE VIEW r_clevel AS 
SELECT
	user_id,
	rec_buy_time,
	datediff( '2019-12-18', rec_buy_time ) AS recen_num,
(
	CASE
			
			WHEN datediff( '2019-12-18', rec_buy_time ) <= 2 THEN
			5 
			WHEN datediff( '2019-12-18', rec_buy_time ) <= 4 THEN
			4 
			WHEN datediff( '2019-12-18', rec_buy_time ) <= 6 THEN
			3 
			WHEN datediff( '2019-12-18', rec_buy_time ) <= 8 THEN
			2 ELSE 1 
		END 
		) AS r_value 
	FROM
		user_Recency;
		

-- 1.建立F视图

CREATE VIEW frenq_value AS 
SELECT
	user_id,
	count( user_id ) AS buy_frenq 
FROM
	temp_trade 
WHERE
	behavior_type = '2' 
GROUP BY
	user_id;


-- 2.建立F等级划分

CREATE VIEW f_clevel AS 
SELECT
	user_id,
	buy_frenq,
(
	CASE
			
			WHEN buy_frenq <= 2 THEN
			1 
			WHEN buy_frenq <= 4 THEN
			2 
			WHEN buy_frenq <= 6 THEN
			3 
			WHEN buy_frenq <= 8 THEN
			4 ELSE 5 
		END 
) AS 'f_values' 
FROM
	frenq_value;
	

-- 将用户整合
-- 1.R平均值


SELECT avg(r_value) as 'r_avg' FROM r_clevel; -- 2.7939

-- 2.F平均值

SELECT avg( f_values ) AS 'f_avg' FROM	f_clevel;-- 2.2606

-- 3.用户八大类等级划分,由于该数据没有M值,故只建立了4个分类
DROP VIEW IF EXISTS RFM_inall;

CREATE VIEW RFM_inall AS 
SELECT
	a.*,
	b.f_values,
(
	CASE 
		WHEN a.r_value > 2.7939 AND b.f_values > 2.2606 THEN '重要高价值客户' 
		WHEN a.r_value < 2.7939 AND b.f_values > 2.2606 THEN '重要唤回客户' 
		WHEN a.r_value > 2.7939 AND b.f_values < 2.2606 THEN '重要深耕客户' 
		WHEN a.r_value < 2.7939 AND b.f_values < 2.2606 THEN '重要挽留客户' 
		END 
) AS user_class 
FROM
	r_clevel a,
	f_clevel b 
WHERE
	a.user_id = b.user_id;
	
SELECT
	count( user_id ) AS user_v,
	user_class 
FROM
	RFM_inall 
GROUP BY
	user_class;


-- 商品指标
-- 商品的点击量 收藏量 加购量 购买次数 购买转化

SELECT	* FROM temp_trade;

SELECT
	item_id,
	sum( CASE WHEN behavior_type = 1 THEN 1 ELSE 0 END ) AS 'pv',
	sum( CASE WHEN behavior_type = 4 THEN 1 ELSE 0 END ) AS 'fav',
	sum( CASE WHEN behavior_type = 3 THEN 1 ELSE 0 END ) AS 'cart',
	sum( CASE WHEN behavior_type = 2 THEN 1 ELSE 0 END ) AS 'buy',
	count( DISTINCT CASE WHEN behavior_type = 2 THEN user_id ELSE NULL END ) / count( DISTINCT user_id ) AS buy_rate 
FROM
	temp_trade 
GROUP BY
	item_id 
ORDER BY
	buy DESC;



SELECT
	item_category,
	sum( CASE WHEN behavior_type = 1 THEN 1 ELSE 0 END ) AS 'pv',
	sum( CASE WHEN behavior_type = 4 THEN 1 ELSE 0 END ) AS 'fav',
	sum( CASE WHEN behavior_type = 3 THEN 1 ELSE 0 END ) AS 'cart',
	sum( CASE WHEN behavior_type = 2 THEN 1 ELSE 0 END ) AS 'buy',
	count( DISTINCT CASE WHEN behavior_type = 2 THEN user_id ELSE NULL END ) / count( DISTINCT user_id ) AS buy_rate 
FROM
	temp_trade 
GROUP BY
	item_category 
ORDER BY
	buy DESC;


-- 每日的分析(1-4,分别表示点击pv、购买buy、加购物车cart、喜欢fav)
SELECT
	dates,
	count( 1 ) AS '每日的总数',
	sum( CASE WHEN behavior_type = 1 THEN 1 ELSE 0 END ) AS 'pv',
	sum( CASE WHEN behavior_type = 2 THEN 1 ELSE 0 END ) AS 'buy',
	sum( CASE WHEN behavior_type = 3 THEN 1 ELSE 0 END ) AS 'cart',
	sum( CASE WHEN behavior_type = 4 THEN 1 ELSE 0 END ) AS 'fav',
	count( DISTINCT CASE WHEN behavior_type = 2 THEN user_id ELSE NULL END ) / count( DISTINCT user_id ) AS buy_rate 
FROM
	temp_trade 
GROUP BY
	dates;
-- 平台指标
-- 行为路径分析
-- 行为路径组建基础视图

DROP VIEW product_user_way;

CREATE VIEW product_user_way AS 
SELECT
	a.* 
FROM
(
	SELECT
		user_id,
		item_id,
		lag ( behavior_type, 4 ) over ( PARTITION BY user_id, item_id ORDER BY date_time ) lag_4,
		lag ( behavior_type, 3 ) over ( PARTITION BY user_id, item_id ORDER BY date_time ) lag_3,
		lag ( behavior_type, 2 ) over ( PARTITION BY user_id, item_id ORDER BY date_time ) lag_2,
		lag ( behavior_type ) over ( PARTITION BY user_id, item_id ORDER BY date_time ) lag_1,
		behavior_type,
		rank ( ) over ( PARTITION BY user_id, item_id ORDER BY date_time DESC ) AS rank_dn # 倒数第几个行为
		
	FROM
		temp_trade
) a

WHERE
	a.rank_dn = 1 
	AND behavior_type = 2
	
	
-- 查询该路径下有多少购买用户数
SELECT
	concat(
		ifnull( lag_4, '空' ),
		"-",
		ifnull( lag_3, '空' ),
		"-",
		ifnull( lag_2, '空' ),
		"-",
		ifnull( lag_1, '空' ),
		"-",
		behavior_type 
	) AS user_way,
	count( DISTINCT user_id ) AS user_count -- 该路径下购买用户数
FROM
	product_user_way 
GROUP BY
	concat(
		ifnull( lag_4, '空' ),
		"-",
		ifnull( lag_3, '空' ),
		"-",
		ifnull( lag_2, '空' ),
		"-",
		ifnull( lag_1, '空' ),
		"-",
	behavior_type 
	);

标签:dates,基于,user,behavior,MySQL,device,电商,type,id
来源: https://blog.csdn.net/weixin_55759540/article/details/117744711