sql

1、所有买家各消费行为对比

#去除重复的购买行为的数据,避免刷单行为
select act

from

(selectcount(user_id) act from user_log where action='0'

union all

selectcount(user_id) act from user_log where action='1'

union all

selectcount(distinct user_id) act from user_log where action='2'

union all

selectcount(user_id) act from user_log where action='3') as temp;

2、男女买家交易对比

#统计女的购买行为的数量

selectcount(action=2) sex

from user_logul 

where gender=0;

#统计男的购买行为的数量

selectcount(action=2) sex

from user_logul 

where gender =1;

将这两个数据传入新表second_data,以便于数据可视化的时候,提升python读取数据库数据的速度

3、男女买家各个年龄段交易对比

从这个步骤开始后,后面的数据都是在原数据表user_id中筛选出日期是双十一的新表ee_data,因为数据较大,后期读取数据的速度非常慢,我就重新筛选了双十一的数据传入新表ee_data。

insert intoee_data select * from user_log ul where month =11 and day =11;

-- 查看女的各个年龄段的数量

selectage_range age, count(gender_age) sex 

from ee_dataed2  

where  gender_age =0 

group byage_range 

order byage_range; #排序

-- 查看男的各个年龄段的数量

selectage_range age, count(gender_age) 

from ee_dataed2  

where  gender_age = 1 

group byage_range 

order byage_range;

4、商品类别交易额对比 思路 先筛选出双十一的数据,选择cat_idaction=2的数量

selected.cat_id ,count( ed.action) count_num

from ee_dataed

whereed.action =2

group byed.cat_id 

order byed.cat_id ;

并且将数据传入新表cat_data,避免读取数据时二次查询,节省时间。

5、各省份的销量对比 思路与前一个相同

selected.province  ,count( ed.action)count_num

from ee_dataed

whereed.action =2

group byed.province  

order bycount_num ;

并且将数据传入新表id_pro_test,避免读取数据时二次查询,节省时间。

6、回头客预测分数对比

-- 不要user_id作为预测特征值。选择前两千条作为数据,

selectage_range ,gender ,merchant_id ,label 

from test t 

where label isnot null 

limit 0,2000;

posted @ 2022-11-14 11:23  –L-m-  阅读(59)  评论(0)    收藏  举报