电商用户行为数据分析

电商用户行为数据分析

基于100万用户的1亿条数据 2017/11/25 - 2017/12/03 用户行为洞察

仪表盘

数据来源说明

本次分析数据来源于阿里天池开放数据集,该平台作为国内权威的公开数据共享平台,聚焦电商、金融等领域的高质量脱敏数据,为学术研究与商业分析提供了可靠的数据支撑。本次使用的数据集规模为3GB,包含约1亿条用户行为记录,覆盖2017年11月25日至12月3日期间的淘宝平台用户行为数据,数据维度完整且时效性强。

从数据字段来看,数据集包含以下核心变量:

字段名 字段含义
user_id 用户唯一标识, 用于区分不同用户的个体行为
category_Id 商品品类ID, 标识商品所属的一级二级分类
item_id 商品唯一ID, 代表具体商品的数字化标识
behavior_type 用户行为类型,包含4类核心行为:pv, cart, fav, buy.直接映射用户从“流量触达”到“最终转化”的关键动作
timestamps 行为发生的时间戳,记录用户行为的具体时间节点,是后续时间序列分析(如时段偏好,转化漏斗时效性)的基础

数据质量层面,该数据集完整度较高,未出现关键字段(user_id, behavior_type)的缺失值,有效避免了因数据缺失导致的分析偏差。本次数据集在预处理方面主要做了下面两个步骤:

  1. 时间格式的转换:将timestamps 字段 转化为“年月日时分秒”的时间格式(如‘2017-11-25 19:00:00“),便于按日,小时维度进行行为趋势分析

  2. 异常时间过滤:数据集中存在少量异常时间戳,本次分析仅保留目标时间段(2017/11/25-2017/12/03)内的数据,确保研究样本的时间一致性与时效性

综上所述,该数据集通过完整的用户行为记录与高质量的数据质量,为本次用户行为路径、转化效率及分层运营分析提供了坚实的数据基础。

分析背景与目标

业务背景

淘宝作为中国头部电商平台,深耕零售电商领域十余年,已构建起覆盖全品类的数字化消费生态,核心服务包括C2C(消费者对消费者)、B2C(企业对消费者)及内容电商等多元模式,用户规模长期稳居亿级量级,是国民级线上消费入口。平台核心品类涵盖服饰美妆、3C数码、家居日用、食品生鲜等高频消费领域,同时通过直播带货、内容种草等创新形式持续拓展新兴消费场景,用户粘性与消费潜力显著。

此次分析主要聚焦于2017年11月25日至12月3日期间淘宝平台100万用户的行为路径数据。从时间维度来看,该周期横跨“双十一” 大促后的用户需求回落期与“双十二”年终大促的蓄水期,用户行为既包含日常消费的延续性特征(如复购,日常浏览),也隐含大促前的决策铺垫动作(如架构收藏,价格对比),具有典型的“促销周期衔接期”研究价值。

平台核心业务目标层面,淘宝在此阶段核心任务是:通过用户行为数据的深度挖掘,识别流量转化链路中的关键节点与流失风险,优化用户从“浏览-兴趣-决策-购买”的全流程体验,为“双十二”大促的流量分配策略、商品推荐逻辑及促销活动设计提供数据支撑,最终实现用户活跃度提升、转化效率优化与GMV(商品交易总额)增长的协同目标。

由于本次分析的数据集中未提供商品名称的详细信息(仅保留商品ID),因此研究重点转向用户行为的量化指标分析,具体包括:

指标名称 细节描述
PV (页面浏览量) 用户对平台页面的总访问次数, 反映流量规模与用户活跃度
UV (独立访客数) 一定周期内访问平台的去重用户数,衡量用户覆盖规模
Cart (加购量) 用户将商品加入购物车的次数,体现消费意愿的初步转化
Favorite(收藏量) 用户收藏商品的数量,反映长期消费兴趣的沉淀
Buy (购买量) 用户实际下单支付的商品数量,代表最终转化结果

通过对上述指标的多维交叉分析(如UV-PV转化率、加购-购买转化率等),可系统性拆解用户从“流量触达”到“最终购买”的行为路径特征,为平台运营策略优化提供实证支撑。

分析目标

本次分析以“用户行为-转化效率-运营策略优化”为主线,通过多维度数据挖掘与指标交叉分析,系统性诊断用户在平台内的行为特征与转化规律,具体目标如下:

  1. 流量与活跃度全景洞察: 基于PV(页面浏览量)、UV(独立访客数)及PV/UV趋势图,量化平台流量规模与用户活跃度的时空分布特征(如日间/夜间高峰、周度波动),识别流量增长潜力区间与活跃用户的行为偏好时段。
  2. 用户行为转化效率诊断: 通过用户行为每日/每时趋势图、购买率(每时/每日)分析,拆解用户从“浏览”到“购买”的全链路转化效率,定位不同时间维度(日/小时)下的转化瓶颈(如早间流量高但购买率低、晚间转化效率峰值时段),明确效率提升的关键场景。
  3. 用户行为路径与流失节点识别: 利用用户行为漏斗分析与路径分析,还原用户从访问到支付的核心路径(如“首页浏览→商品详情页→加购→支付”),量化各环节流失率(如加购-支付流失率、收藏-复购流失率),识别用户决策链路中的关键阻碍点(如页面跳转复杂、价格敏感度高)。
  4. 用户分层运营策略制定:基于RFM模型(最近购买时间R、购买频次F、消费金额M),将用户划分为“高价值用户(高R/F/M)”“潜力用户(高F/低R)”“沉睡用户(低R/F/M)”等群体,针对性提出发展(高潜力用户激励)、挽留(沉睡用户唤醒)、保持(高价值用户权益维护)策略,提升用户生命周期价值(LTV)

图表分析

用户流量分析

从“PV&UV数量图”可见,每日PV均维持在900万至1000万次区间(10M量级),整体波动幅度小于5%,显示平台在该周期内流量承载能力稳定,内容或服务的用户触达频次保持高位。其中,多个日期的PV峰值接近1000万次,体现出核心页面或功能的高频访问特性。UV规模显著低于PV,每日独立访客数稳定在0.5万左右(0.5M),红色柱状图显示各日UV数值几乎无差异,表明期间访问用户群体高度重叠,新用户引入能力较弱,或流量来源集中于存量用户。结合PV与UV的比例关系(平均每UV贡献约1800-2000次页面浏览),用户粘性或单用户深度访问行为表现突出。

“PV/UV趋势图”呈现周期内比值在12.0至14.0之间波动的特征,反映出不同日期用户访问深度的差异:

  • 峰值阶段(14.0附近):可能对应特定营销活动日、热点内容上线或周末用户活跃时段,用户在单次访问中浏览更多页面,体现内容吸引力或交互引导的有效性。
  • 谷值阶段(12.0附近):或受工作日用户行为习惯影响(如工作日碎片化时间导致浏览深度下降),或页面加载效率、推荐算法调整等影响用户体验,导致单UV浏览页数减少。

从趋势走向看,前半周期(11.25-12.01)比值相对平稳,后半周期(12.02-12.03)出现小幅回落,需结合同期运营动作(如版本更新、流量投放策略调整)或外部环境(如行业事件)进一步验证具体诱因。

用户行为每日详细分析

用户行为每日详细分析(折线图) 可见,期间用户行为呈现“高流量触达、高兴趣沉淀、低转化效率”的三元特征,具体表现为四大行为指标的规模与占比分化显著:

  • 行为规模排序PV(页面浏览量) > Cart(加购量) > Fav(收藏量) > Buy(购买量)
    • PV日均值超800K(高峰时段突破1000K),占行为总量的45%-50%,是用户流量触达的核心载体;
    • Cart日均值约800K(占比40%-45%),为兴趣转化的核心动作;
    • Fav日均值约600K(占比25%-30%),反映用户长期消费兴趣的沉淀;
    • Buy日均值仅约200K(占比10%),显著低于前三者,表明“流量-兴趣-转化”链路存在明显断层。
  • 日内波动共性:所有行为指标均呈现“日间高峰-凌晨低谷”的周期性规律,与用户日常作息高度吻合。其中,PVCart在**10:00-12:00(午间碎片化浏览)19:00-22:00(晚间深度决策)**出现峰值(PV峰值超1000K,Cart峰值超900K);Fav峰值时段与Cart基本重叠,但数值相对较低(峰值约700K)。值得关注的是,Buy的峰值滞后于Cart约2-3小时(如Cart在20:00达峰,Buy在22:00-23:00达峰),符合“加购后决策”的用户行为逻辑。

用户行为

用户行为每时分析(折线图) 进一步细化了用户在不同时间粒度下的行为分布,核心结论如下:

  • 24小时行为周期规律:用户活跃高峰集中于10:00-12:00(午间休闲时段)和19:00-22:00(晚间黄金消费时段),两时段内PVCart均保持在800K以上(PV峰值超1000K,Cart峰值超900K),Fav峰值约700K;凌晨0:00-5:00为用户行为低谷期(PVCart均低于300K),仅占全天行为量的10%以下。
  • 行为类型与时段的强关联性
    • 午间高峰(10:00-12:00)以PV为主(占比超60%),反映用户利用碎片化时间浏览商品;
    • 晚间高峰(19:00-22:00)Cart占比提升至45%以上,表明用户进入“深度浏览-兴趣转化”阶段;
    • 凌晨低谷期行为量极低,主要为少量“惯性浏览”用户(如未退出APP的用户)。

用户行为每时购买率(柱状图)日均购买率约0.15(15%浏览用户最终购买),但小时级波动显著,呈现“凌晨低谷→白天阶梯式回升→午间爆发→傍晚缓降”的周期性特征,与大促节点及用户活跃时段高度吻合。

  1. 低谷期(6:00-7:00,单日最低值0.1264)购买率触达全周期最低点(0.1264),较均值低16%,对应全天用户活跃度低谷时段。

    凌晨至清晨用户活跃度极低,以深度睡眠或未开启购物场景为主,浏览行为极少,导致转化基数不足;结合历史数据,该时段Cart(加购率)与Fav(收藏率)同步处于低位,反映用户主动消费意愿基本停滞,符合自然作息规律。

  2. 稳步回升期(8:00-10:00,0.15→0.22)

    购买率从0.15逐步攀升至0.22,3小时内涨幅达47%,斜率显著高于其他时段。用户陆续进入清醒状态,通勤、早餐等碎片化时间开启轻度浏览,叠加部分商家提前开启预热活动(如定时优惠券、早鸟提醒),吸引价格敏感型用户试探性加购;此时段Cart率环比提升20%,显示“浏览→决策”链路效率提升,用户从“持币观望”转向“轻量化决策”。

  3. 爆发期(10:00-12:00,峰值0.2661,全周期最高)

    1小时内购买率骤升至0.2661,较均值高出77%,形成陡峭峰值;同期Cart率、Fav率分别达全天峰值(环比增幅超30%),且12:00-14:00留存购买率(次日复访转化)显著高于其他时段。

    推测与大促核心节点(如“双十二”预售正式开启、限时秒杀活动上线)直接相关,平台强运营动作(如弹窗提醒、倒计时弹窗)唤醒沉睡用户,推动冲动型消费;午间休息时段用户具备完整购物时间,叠加“早买早优惠”心理,形成“浏览→加购→下单”的高效转化闭环,验证大促节点对即时转化的强刺激效应。

  4. 高位缓降期 (13:00-22:00,0.22→0.17)

    峰值后缓慢回落,维持在0.17-0.22区间波动,20:00-22:00出现次高峰(0.20),反映晚间休闲时段的持续性消费需求。下午至晚间用户活跃度稳定,长尾流量持续转化,部分未在午间完成决策的用户通过对比价格、查看评价完成最终下单;次高峰与晚间直播带货、促销信息二次触达等场景相关,体现运营动作对全时段转化的持续性拉动。

漏斗模型

核心路径转化效率:入口层(PV)流量基准值为1,兴趣层(PV→Fav+Cart)转化率9.39%,显示用户初步兴趣强度;决策层(Fav+Cart→Buy)转化率23.94%,表明收藏/加购用户具备较高购买意向;直达路径(PV→Buy)转化率仅2.25%,反映高意向即时转化能力较弱。

  • 分层运营:流量端提升精准触达,兴趣端简化互动路径,决策端优化购物车与结算体验;
  • 数据验证:追踪各环节转化动态,结合用户调研补充定性洞察,形成迭代闭环。

路径分析

从用户行为路径分析的饼图数据来看,用户在平台上的购买路径呈现显著的差异化分布特征。其中,“浏览后购买”与“直接购买”构成核心转化路径,分别以49.29%和26.77%的占比占据绝对主导地位,二者合计贡献近76.06%的整体购买转化,反映出用户更倾向于通过直观浏览或直接决策完成交易。其次,“添加后购买”(3.96%)与“浏览添加后购买”(13.26%)作为中间环节转化路径,体现出购物车工具对部分用户的决策促进作用,其中“浏览添加后购买”通过“浏览-加购-转化”的完整链路形成有效补充,占比约为“添加后购买”的3.35倍,显示加购行为对提升转化率存在正向影响。值得注意的是,“收藏添加后购买”(0.10%)与“浏览收藏添加后购买”(0.70%)两条涉及收藏功能的路径占比极低,合计不足1%,表明收藏行为在当前用户转化过程中尚未形成显著驱动效应,可能反映出收藏功能的用户使用粘性或场景匹配度存在优化空间。整体来看,平台用户购买行为以“即时决策”和“浏览后直接转化”为主要模式,基于购物车的加购环节具备一定转化价值,而收藏相关的深度互动路径尚未充分发挥效能,需针对性强化功能场景设计以提升用户转化效率。

RFM

从用户RFM模型分布来看,当前用户结构呈现差异化特征:发展用户以42.86%的占比成为规模最大的群体,反映平台具备较强的用户增长潜力但尚未完全转化为高价值用户;挽留用户占比38.96%,显示存在近四成用户面临流失风险,需重点关注其活跃度与需求变化;价值用户虽仅占14.53%,但作为贡献核心商业价值的群体,是精细化运营的核心对象;保持用户占比6.67%,需通过持续触达巩固其忠诚度。整体来看,用户结构呈现“发展中用户为主、挽留需求突出、价值用户稀缺”的特征,建议针对不同群体匹配差异化运营策略,优先提升价值用户的留存转化效率,同时加大发展用户的价值激活与挽留用户的流失干预,以实现用户生命周期价值的整体提升。

SQL Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#创建数据库
create database taobao;
use taobao;

#创建表
create table user_behavior (user_id int(9), item_id int(9), category_id int(9), behavior_type varchar(5), timestamps int(14) );

select * from user_behavior limit 10;

### 数据预处理 ###

#检查空值
select * from user_behavior where user_id is null;
select * from user_behavior where item_id is null;
select * from user_behavior where category_id is null;
select * from user_behavior where behavior_type is null;
select * from user_behavior where timestamps is null;

#检查重复值
select user_id, item_id, timestamps from user_behavior group by user_id, item_id, timestamps having count(*) > 1;

#去重
alter table user_behavior add id int first; #添加一个辅助字段
alter table user_behavior modify id int primary key auto_increment;# 新增 id 字段 自增
select * from user_behavior limit 5;

delete user_behavior from user_behavior,(
select user_id, item_id, timestamps, min(id) as id from user_behavior group by user_id, item_id, timestamps having count(*) > 1
) t2
where user_behavior.user_id = t2.user_id and
user_behavior.item_id = t2.item_id and
user_behavior.timestamps = t2.timestamps and
user_behavior.id > t2.item_id;

#添加日期
#更改buffer值
show VARIABLES like '_buffer%';
set GLOBAL innodb_buffer_pool_size =1070000000;

#添加datatime
alter table user_behavior add datetimes TIMESTAMP(0);
update user_behavior set datetimes=from_unixtime(timestamps);
select * from user_behavior limit 5;

#将datetimes进行 细加工 加三个字段
alter table user_behavior add dates char(10);
alter table user_behavior add times char(8);
alter table user_behavior add hours char(2);


update user_behavior set dates = substring(datetimes,1,10);
update user_behavior set times = substring(datetimes,12,8);
update user_behavior set hours = substring(datetimes,12,2);
select * from user_behavior limit 5;

#清理异常值
select max(datetimes), min(datetimes) from user_behavior;
delete from user_behavior where datetimes < '2017-11-25 00:00:00' or datetimes > '2017-12-03 23:59:59';

select * from user_behavior where dates is null;
delete from user_behavior where dates is null;


### 获客分析 ##
create table acq_user (
dates char(10),
pv int(9),
uv int(9),
puv decimal(10,1)
);

insert into acq_user
select dates, count(*) 'pv', #获取pv量
count(distinct user_id) 'uv', #获取uv量
round(count(*)/count(distinct user_id),1) 'pv/uv' #获取pv/uv率
from user_behavior where behavior_type = 'pv' group by dates;

select * from acq_user;



### 留存分析 ###

#留存率
create table retention_rate(
dates char(10),
retention_1 float
);

insert into retention_rate
select a.dates,
count(if(datediff(b.dates,a.dates)=1,b.user_id,null))/count(if(datediff(b.dates,a.dates)=0,b.user_id,null)) retention_1
from
(select user_id, dates from user_behavior group by user_id, dates) a,
(select user_id, dates from user_behavior group by user_id, dates) b
where a.user_id = b.user_id and a.dates<=b.dates
group by a.dates;

select * from retention_rate;

# 跳失率-用户只浏览了一次 -- 88个
# 跳转率 = 88/89660650

select a.cnt/(select sum(pv) sum_pv from acq_user) from (
select count(user_id) cnt from user_behavior group by user_id having count(behavior_type) = 1
) a;

###行为分析
#时序分析 by hours

create table hourstimes_behav(
date char(10),
hours char(2),
pv int,
cart int,
fav int,
buy int);
insert into hourstimes_behav
select dates, hours ,
count(if(behavior_type='pv', behavior_type, null)) 'pv',
count(if(behavior_type='cart', behavior_type, null)) 'cart',
count(if(behavior_type='fav', behavior_type, null)) 'fav',
count(if(behavior_type='buy', behavior_type, null)) 'buy'
from user_behavior
group by dates, hours
order by dates, hours;

#统计个behavior type 的用户数量
create table user_beha_type_num (
behavior_type varchar(5),
num int);

insert into user_beha_type_num
select behavior_type, count(distinct user_id) num from user_behavior
group by behavior_type
order by behavior_type desc;


#统计各个behavior type 的类型
create table beha_type_num (
behavior_type varchar(5),
num int);
insert into beha_type_num
select behavior_type, count(user_id) num from user_behavior
group by behavior_type
order by behavior_type desc;

##### 行为路径分析 ####

drop view user_behavior_view;
drop view user_behavior_standard;
drop view user_path;
drop view path_cnt;

create view user_behavior_view as
select user_id, item_id,
count(if(behavior_type='pv', behavior_type, null)) 'pv',
count(if(behavior_type='cart', behavior_type, null)) 'cart',
count(if(behavior_type='fav', behavior_type, null)) 'fav',
count(if(behavior_type='buy', behavior_type, null)) 'buy'
from user_behavior
group by user_id, item_id;

#将用户的行为进行standardized
create view user_behavior_standard as
select user_id, item_id,(case when pv>0 then 1 else 0 end) 已浏览,
(case when fav>0 then 1 else 0 end) 已收藏,
(case when cart>0 then 1 else 0 end) 已添加,
(case when buy>0 then 1 else 0 end) 已购买
from user_behavior_view;

create view user_path as
select *, concat(已浏览,已收藏,已添加,已购买) 用户购买路径
from user_behavior_standard
where 已购买>0;

create view path_cnt as
select 用户购买路径, count(*) cnt from user_path
group by 用户购买路径
order by cnt desc;

create table pathcode(
path_type char(4),
description varchar(40)
);

insert into pathcode
values('0001','直接购买'),
('1001','浏览后购买'),
('0011','添加后购买'),
('1011','浏览添加后购买'),
('0101','收藏后购买'),
('1101','浏览收藏后购买'),
('0111','收藏添加后购买'),
('1111','浏览收藏添加后购买');

select * from path_cnt t1 join pathcode t2 on t1.用户购买路径 = t2.path_type
order by cnt;

create table user_path_result(
path_type char(4),
description varchar(40),
num int);

insert into user_path_result
select path_type, description, cnt
from path_cnt t1 join pathcode t2 on t1.用户购买路径 = t2.path_type;

##### RFM #######

# Recency 最近一次购买 & Frequency 购买频率
create table rfmModel(
user_id int, recency char(10) , frequency int
);

insert into rfmModel
select user_id, max(dates) recency, count(user_id) frequency from user_behavior where behavior_type='buy'
group by user_id order by 2 desc, 3 desc;


#根据recency 进行用户分层
alter table rfmModel add column rscore int;
update rfmModel set rscore = (case when recency = '2017-12-03' then 5
when recency in ('2017-12-01','2017-12-02') then 4
when recency in ('2017-11-29','2017-11-30') then 3
when recency in ('2017-11-27','2017-11-28') then 2
else 1 end
);

#根据frequency 进行用户分层
alter table rfmModel add column fscore int;
update rfmModel set fscore = (case when frequency between 100 and 262 then 5
when frequency between 50 and 99 then 4
when frequency between 20 and 49 then 3
when frequency between 5 and 19 then 2
else 1 end);


set @favg = null;
set @ravg = null;
select avg(fscore) into @favg from rfmModel;
select avg(rscore) into @ravg from rfmModel;

alter table rfmModel add column category varchar(40);
update rfmModel
set category = case
when fscore>@favg and rscore >@ravg then '价值用户'
when fscore>@favg and rscore <@ravg then '保持用户'
when fscore<@favg and rscore >@ravg then '发展用户'
when fscore<@favg and rscore <@ravg then '挽留用户'
end;


#### 商品热度排行 ####
#种类热度分类 Top 10
create table popular10_categories(
category_id int,
pv int);
insert into popular10_categories
select category_id, count(if(behavior_type='pv', behavior_type, null)) '品类浏览量'from user_behavior
group by category_id order by 2 desc limit 10;

#商品热度 Top 10
create table popular10_items(
item_id int,
pv int);
insert into popular10_items
select item_id, count(if(behavior_type='pv',behavior_type,null)) '商品浏览量' from user_behavior
group by item_id order by 2 desc limit 10;

#品类商品热度
create table popular10_cateitems(
category_id int,
item_id int,
pv int);
insert into popular10_cateitems
select category_id, item_id, 品类商品浏览量 from (
select category_id, item_id,
count(if(behavior_type='pv', behavior_type, null)) '品类商品浏览量',
rank() over(partition by category_id order by '品类商品浏览量' desc) rk
from user_behavior
group by category_id, item_id
order by 3 desc
) t1
where t1.rk = 1
order by t1.品类商品浏览量 desc
limit 10;

#### 商品转化率 ####
#商品转化率
create table item_convert_rate(
item_id int, pv int, fav int, cart int, buy int, purchase_item_rate float
);
insert into item_convert_rate
select item_id, count(if(behavior_type='pv', behavior_type,null)) pv,
count(if(behavior_type='fav', behavior_type,null)) fav,
count(if(behavior_type='cart',behavior_type,null)) cart,
count(if(behavior_type='buy',behavior_type,null)) buy,
count(if(behavior_type='buy',behavior_type,null))/count(distinct user_id) 商品转化率
from user_behavior
group by item_id
order by 商品转化率 desc;

#品类转化率

create table category_convert_rate(
item_id int, pv int, fav int, cart int, buy int, purchase_category_rate float
);
insert into category_convert_rate
select category_id, count(if(behavior_type='pv', behavior_type,null)) pv,
count(if(behavior_type='fav', behavior_type,null)) fav,
count(if(behavior_type='cart',behavior_type,null)) cart,
count(if(behavior_type='buy',behavior_type,null)) buy,
count(if(behavior_type='buy',behavior_type,null))/count(distinct user_id) 品种转化率
from user_behavior
group by category_id
order by 品种转化率 desc;

select * from popular10_cateitems;


drop table tendency;
create table tendency(
dh char(13),
pv int,
fav int,
cart int,
buy int
);
insert into tendency
select concat(date,' ',hours) dv, pv, fav, cart, buy from hourstimes_behav;

select * from hourstimes_behav;

select hours, (sum(buy) / sum(pv)) ratio from hourstimes_behav group by hours;

select count(1) from user_behavior #100095129

select num/100095129 from beha_type_num where behavior_type='pv';
select num/100095129 from beha_type_num where behavior_type='cart';



#漏斗模型
create table funnelModel(
pv float,
pv2favcart float,
favcart2buy float,
pv2buy float
);
insert into funnelModel
select pv/pv pv,
(fav+cart)/pv pv2favcart,
buy/(fav+cart) favcart2buy,
buy/pv pv2buy from (
select sum(if(behavior_type='pv',num,null)) pv,
sum(if(behavior_type='fav',num,null)) fav,
sum(if(behavior_type='cart',num,null)) cart,
sum(if(behavior_type='buy',num,null)) buy
from beha_type_num
)t1;

create table tunnelModel2 (
num float,
type varchar(15)
);
insert into tunnelModel2
select pv*100 num , 'pv' type from funnelModel
union all
select pv2favcart*100 num, 'pv2favcart' type from funnelModel
union all
select favcart2buy*100 num, 'favcart2buy' type from funnelModel
union all
select pv2buy num , 'pv2buy' type from funnelModel;

describe user_behavior