- 2021-04-14 发布 |
- 37.5 KB |
- 0页
SQL 综合练习讲解:专题四会员特征分析
取 2017 年 8 月份,会员的消费特征分析,对比会员 VS 非会员:1、 平均客单价
2、 不同客单价区间订单,销售金额分布【100 以下,以 20 为单位划分,100-200 按 50
划分,200 以上这几个区间段】
3、 订单购买的商品数分布【每个订单中,购买 1,2,3,4,5,。。。件】
4、 周末 VS 非周末 中的会员 VS 非会员 的订单量占比分布;
业务背景和价值说明:
项目的实战背景是二家超市的真实数据,数据时间段是从 20160101 到 20171031。
超市的主要商业场景
通过对比分析,来发现会员与非会员的价值区别
构建会员标签,进行会员的精准营销
商业知识点思考:
会员对企业实现数据化经营(特别是线下)是核心
如何对会员数据进行更深入数据分析,不断打会员打上标签,从而为相关业务部门提供决策参考
SQL 知识点:
Case when
子查询
变量定义
-- 平均客单价
select case when t.MemberID is null then '非会员' else '会员' end as
member_type
,count(distinct t.SheetID) as order_number
,sum(t.PayValue) as pay_value
,sum(t.PayValue)/count(distinct t.SheetID) as avg_order
from demo.orderlist t
where t.SDate between '20170801' and '20170831'
and t.ShopID='CDLG'
group by case when t.MemberID is null then '非会员' else '会员' end
-- 客单价区间订单
select case when t.MemberID is null then '非会员' else '会员' end as
member_type
,case when t.PayValue<=20 then '0-20]'
when t.PayValue>20 and t.PayValue<=40 then '(20-40]'
when t.PayValue>40 and t.PayValue<=60 then '(40-60]'
when t.PayValue>60 and t.PayValue<=80 then '(60-80]'
when t.PayValue>80 and t.PayValue<=100 then '(80-100]'
when t.PayValue>100 and t.PayValue<=150 then '(100-150]'
when t.PayValue>150 and t.PayValue<=200 then '(150-200]'
when t.PayValue>200 then '(200-]'
end as order_type
,count(distinct t.SheetID) as order_number
,sum(t.PayValue) as pay_value
from demo.orderlist t
where t.SDate between '20170801' and '20170831'
and t.ShopID='CDLG'
group by case when t.MemberID is null then '非会员' else '会员' end
,case when t.PayValue<=20 then '0-20]'
when t.PayValue>20 and t.PayValue<=40 then '(20-40]'
when t.PayValue>40 and t.PayValue<=60 then '(40-60]'
when t.PayValue>60 and t.PayValue<=80 then '(60-80]'
when t.PayValue>80 and t.PayValue<=100 then '(80-100]'
when t.PayValue>100 and t.PayValue<=150 then '(100-150]'
when t.PayValue>150 and t.PayValue<=200 then '(150-200]'
when t.PayValue>200 then '(200-]'
end;
-- 订单购买的商品数分布【每个订单中,购买1,2,3,4,5,。。。件】
select t.Qty
,case when t1.MemberID is null then '非会员' else '会员' end
as member_type
,count(distinct t1.SheetID) as order_nubmer
from demo.orderitem t
join demo.orderlist t1 on t.SheetID = t1.SheetID
where t.SDate between '20170801' and '20170831'
and t.ShopID='CDLG'
group by t.Qty
,case when t1.MemberID is null then '非会员' else '会员' end;
-- 周末 VS 非周末 中的会员 VS非会员 的订单量占比分布
select w_day
,member_type
,order_number
,order_number/@total_order as per
from
(select case when weekday(SDate) in (5,6) then '周末' else '非周末' end
as w_day
申明敬告: 本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
文档介绍
SQL 综合练习讲解:专题四会员特征分析
SQL 综合练习讲解:专题四会员特征分析
取 2017 年 8 月份,会员的消费特征分析,对比会员 VS 非会员:1、 平均客单价
2、 不同客单价区间订单,销售金额分布【100 以下,以 20 为单位划分,100-200 按 50
划分,200 以上这几个区间段】
3、 订单购买的商品数分布【每个订单中,购买 1,2,3,4,5,。。。件】
4、 周末 VS 非周末 中的会员 VS 非会员 的订单量占比分布;
业务背景和价值说明:
项目的实战背景是二家超市的真实数据,数据时间段是从 20160101 到 20171031。
超市的主要商业场景
通过对比分析,来发现会员与非会员的价值区别
构建会员标签,进行会员的精准营销
商业知识点思考:
会员对企业实现数据化经营(特别是线下)是核心
如何对会员数据进行更深入数据分析,不断打会员打上标签,从而为相关业务部门提供决策参考
SQL 知识点:
Case when
子查询
变量定义
-- 平均客单价
select case when t.MemberID is null then '非会员' else '会员' end as
member_type
,count(distinct t.SheetID) as order_number
,sum(t.PayValue) as pay_value
,sum(t.PayValue)/count(distinct t.SheetID) as avg_order
from demo.orderlist t
where t.SDate between '20170801' and '20170831'
and t.ShopID='CDLG'
group by case when t.MemberID is null then '非会员' else '会员' end
-- 客单价区间订单
select case when t.MemberID is null then '非会员' else '会员' end as
member_type
,case when t.PayValue<=20 then '0-20]'
when t.PayValue>20 and t.PayValue<=40 then '(20-40]'
when t.PayValue>40 and t.PayValue<=60 then '(40-60]'
when t.PayValue>60 and t.PayValue<=80 then '(60-80]'
when t.PayValue>80 and t.PayValue<=100 then '(80-100]'
when t.PayValue>100 and t.PayValue<=150 then '(100-150]'
when t.PayValue>150 and t.PayValue<=200 then '(150-200]'
when t.PayValue>200 then '(200-]'
end as order_type
,count(distinct t.SheetID) as order_number
,sum(t.PayValue) as pay_value
from demo.orderlist t
where t.SDate between '20170801' and '20170831'
and t.ShopID='CDLG'
group by case when t.MemberID is null then '非会员' else '会员' end
,case when t.PayValue<=20 then '0-20]'
when t.PayValue>20 and t.PayValue<=40 then '(20-40]'
when t.PayValue>40 and t.PayValue<=60 then '(40-60]'
when t.PayValue>60 and t.PayValue<=80 then '(60-80]'
when t.PayValue>80 and t.PayValue<=100 then '(80-100]'
when t.PayValue>100 and t.PayValue<=150 then '(100-150]'
when t.PayValue>150 and t.PayValue<=200 then '(150-200]'
when t.PayValue>200 then '(200-]'
end;
-- 订单购买的商品数分布【每个订单中,购买1,2,3,4,5,。。。件】
select t.Qty
,case when t1.MemberID is null then '非会员' else '会员' end
as member_type
,count(distinct t1.SheetID) as order_nubmer
from demo.orderitem t
join demo.orderlist t1 on t.SheetID = t1.SheetID
where t.SDate between '20170801' and '20170831'
and t.ShopID='CDLG'
group by t.Qty
,case when t1.MemberID is null then '非会员' else '会员' end;
-- 周末 VS 非周末 中的会员 VS非会员 的订单量占比分布
select w_day
,member_type
,order_number
,order_number/@total_order as per
from
(select case when weekday(SDate) in (5,6) then '周末' else '非周末' end
as w_day
查看更多