• 0 Bytes
  • 2021-04-14 发布

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
  • 0页
  • 当前文档由用户上传发布,收益归属用户
  • 下载文档
  1. 1、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  2. 2、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  3. 文档侵权举报QQ:3215808601
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