SQL 综合练习详解专题6:商品 ABC 分析

SQL 综合练习详解专题六:商品 ABC 分析
选择一个月,选择一家门店:
对商品进行按月汇总并按销售额进行排名,ABC 分类规则:A 类商品占门店前 60%的销售,
B 类商品占后 30%,C 类商品占后 10%。
1、计算出 ABC 各类商品 SKU 数,给每个商品 ABC 的标签。
# 要点说明,我们需要定义一个变量,用于记录商品的累计值
# 然后再对进行相关分类
select t1.ShopID
,GoodsID
,sales_value
,total_sales
,max_vlaue
,total_sales/max_vlaue
,case when total_sales/max_vlaue <=0.6 then 'A'
when total_sales/max_vlaue <=0.8 and
total_sales/max_vlaue>0.6 then 'B'
when total_sales/max_vlaue > 0.8 then 'C' end
as type_1
from (select ShopID
,a.GoodsID
,a.sales_value
,(@total_sales := @total_sales + a.sales_value) as
total_sales
from
( select t1.GoodsID
,t1.ShopID
,sum(t1.SaleValue) as sales_value
from demo.orderitem as t1
where t1.SDate between 20160101 and 20160131
and t1.ShopID = 'WDGC'
group by t1.GoodsID
,t1.ShopID
order by sum(t1.SaleValue) desc
) as a
join (select @total_sales := 0) as x
) t1
join (select t1.ShopID
,sum(t1.SaleValue) as max_vlaue
 from demo.orderitem as t1
申明敬告: 本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。

文档介绍

SQL 综合练习详解专题6:商品 ABC 分析

SQL 综合练习详解专题六:商品 ABC 分析
选择一个月,选择一家门店:
对商品进行按月汇总并按销售额进行排名,ABC 分类规则:A 类商品占门店前 60%的销售,
B 类商品占后 30%,C 类商品占后 10%。
1、计算出 ABC 各类商品 SKU 数,给每个商品 ABC 的标签。
# 要点说明,我们需要定义一个变量,用于记录商品的累计值
# 然后再对进行相关分类
select t1.ShopID
,GoodsID
,sales_value
,total_sales
,max_vlaue
,total_sales/max_vlaue
,case when total_sales/max_vlaue <=0.6 then 'A'
when total_sales/max_vlaue <=0.8 and
total_sales/max_vlaue>0.6 then 'B'
when total_sales/max_vlaue > 0.8 then 'C' end
as type_1
from (select ShopID
,a.GoodsID
,a.sales_value
,(@total_sales := @total_sales + a.sales_value) as
total_sales
from
( select t1.GoodsID
,t1.ShopID
,sum(t1.SaleValue) as sales_value
from demo.orderitem as t1
where t1.SDate between 20160101 and 20160131
and t1.ShopID = 'WDGC'
group by t1.GoodsID
,t1.ShopID
order by sum(t1.SaleValue) desc
) as a
join (select @total_sales := 0) as x
) t1
join (select t1.ShopID
,sum(t1.SaleValue) as max_vlaue
 from demo.orderitem as t1
查看更多

相关文章

您可能关注的文档