四. 销量的影响因素分析

SQL代码

千台车故障率和销量
SELECT
substr(period_wid,1,6) as period_mon,
sum(mtd_issue_car_num) as mtd_issue,
sum(ytd_issue_car_num) as ytd_issue,
sum(mtd_sales_car_num) as mtd_sales,
sum(last_sales_car_num) as last_sales,
sum(ytd_sales_car_num) as ytd_sales
FROM DMR.DMR_SAL_ISSUE_ANALYSIS_MLY_REP
where brand=‘I0’ and substr(period_wid,1,6) >= 201701
group by substr(period_wid,1,6)

库存
SELECT
substr(period_wid,1,6) as mon,
avg(new_stockqty) as stockqty,
avg(new_stockprice) as stockprice
FROM dmk.dmk_sal_stockbase_dtl
where l2=‘I0’ and substr(period_wid,1,6) >= 201701
group by substr(period_wid,1,6)

经销商数量
SELECT
substr(period_wid,1,6) as mon,
COUNT(DISTINCT dealer_name)
FROM DMK.dmk_sal_actual_sales_dtl
where brand=‘I0’ and substr(period_wid,1,6) >= 201701
group by substr(period_wid,1,6)

交期周期
CREATE TABLE dmk.dmk_sales_dtl_test1 as
select
cast(concat(substr(a.ztftgr,1,4),substr(a.ztftgr,6,2)) as BIGINT) as ztftgr_mon,
a.date7
from DMK.DMK_SAL_DELIVERY_TIME_DTL a
left join dim.dim_product_d b
on b.item_code=a.matnr
where b.l2=‘I0’

select
ztftgr_mon,
avg(date7) as cycle
FROM dmk.dmk_sales_dtl_test1
where ztftgr_mon >= 201701
group by ztftgr_mon

老客户复购
CREATE TABLE dmk.dmk_sales_dtl_test as
SELECT a.period_wid ,
a.brand ,
a.car_model ,
a.qty ,
case when b.creatdate < tmp.new_confirmdate and tmp.FORMTYPE in(‘2’,‘4’) and a.qty = ‘1’ then 1
when b.creatdate < tmp.new_confirmdate and tmp.FORMTYPE in(‘2’,‘4’) and a.qty = ‘-1’ then -1
else 0 end as qty_oldcustomer
FROM DMK.dmk_sal_actual_sales_dtl a
left join (select crm_customer_code,crm_customer_id,NEW_VECHICLEINFO_ID,min(NEW_FORMTYPE) FORMTYPE,
min(regexp_replace(new_confirmtime,’-’,’’)) new_confirmdate
from(select *,row_number() over(PARTITION BY crm_customer_id,NEW_VECHICLEINFO_ID,NEW_FORMTYPE ORDER BY new_confirmtime) RN
from DMK.dmk_sal_actual_sales_dtl) t
where rn=1
group by crm_customer_code,crm_customer_id,NEW_VECHICLEINFO_ID) tmp
on a.crm_customer_id=tmp.crm_customer_id and a.NEW_VECHICLEINFO_ID=tmp.NEW_VECHICLEINFO_ID
LEFT JOIN
(SELECT new_accountid,new_accountlevel,createdon,from_unixtime(unix_timestamp(createdon),‘yyyyMMdd’) as creatdate,t.new_salebu_id,
row_number() OVER (PARTITION BY new_accountid,new_salebu_id ORDER BY createdon DESC,nvl(t.new_accountlevel,-1) desc ) RN
from crm.new_sale_organizationbase t) b
on a.crm_customer_id = b.new_accountid
and a.bd_id= b.new_salebu_id and b.rn=1
where a.brand=‘I0’ and substr(a.period_wid,1,6) >= 201701

SELECT
substr(period_wid,1,6) as period_mon,
sum(qty) as qty,
sum(qty_oldcustomer) as oldcustomer
FROM dmk.dmk_sales_dtl_test
group by substr(period_wid,1,6)

发布了30 篇原创文章 · 获赞 0 · 访问量 349

猜你喜欢

转载自blog.csdn.net/hua_chang/article/details/105034085