删除备份版本notebook
This commit is contained in:
@@ -1,228 +0,0 @@
|
||||
-- Databricks notebook source
|
||||
create or replace temporary view brand_province_config -- brand配置表
|
||||
as
|
||||
select upper(`brand`) as brand, `province` as province, datasource as data_source from dwd.dwd_gnd_merge_data_brand_province
|
||||
|
||||
-- COMMAND ----------
|
||||
|
||||
create or replace temporary view market_province_config --market 配置表
|
||||
as
|
||||
select market, province, datasource as data_source from dwd.dwd_gnd_merge_data_brand_market
|
||||
|
||||
-- COMMAND ----------
|
||||
|
||||
insert overwrite dws.dws_external_merge_data_config_special
|
||||
-- LOCATION 'abfss://master@azcdatalakeprd.dfs.core.chinacloudapi.cn/DWS/dws_external_merge_data_config_special' --prd
|
||||
-- LOCATION 'abfss://master@retaildlstoragetest.dfs.core.chinacloudapi.cn/DWS/dws_external_merge_data_config_special' --test
|
||||
with pack_and_brand ( --brand 转 pack
|
||||
select
|
||||
upper(brandnamee) brand_name
|
||||
,ims_pack_cod PACK_COD --取所有code带出market
|
||||
from dwd.dwd_td_imscode_azcode
|
||||
where ims_pack_cod is not null and startswith(ims_pack_cod,'0')
|
||||
and upper(brandnamee) in (select brand from brand_province_config group by 1 )--取出在配置表中的pack
|
||||
group by 1,2
|
||||
)
|
||||
,pack_to_market (
|
||||
select
|
||||
a.PACK_COD
|
||||
,MARKET
|
||||
from dm.dm_td_external_market_pack_mapping a
|
||||
inner join pack_and_brand b on a.PACK_COD = b.pack_cod --取出配置表中的brand对应的 market
|
||||
where DATA_SOURCE in ( 'AIA(Monthly)')--只取 AIA中的市场,chpa的市场太多
|
||||
and lower(a.MARKET) not like '%all market%'
|
||||
and market not in (
|
||||
'RE Extended Market'
|
||||
,'RE Market'
|
||||
,'RE Market (Global)'
|
||||
,'Pulmicort VBP Benchmark Market'
|
||||
,'Respules Market'
|
||||
)
|
||||
group by 1,2
|
||||
)
|
||||
,market_to_pack ( -- 获取上述market中所有的pack
|
||||
select
|
||||
market
|
||||
,pack_cod
|
||||
from dm.dm_td_external_market_pack_mapping a
|
||||
where DATA_SOURCE in ( 'AIA(Monthly)','IQVIA-CHPA(Monthly)')--AIA和chpa的市场
|
||||
and market in (select market from pack_to_market group by 1)
|
||||
group by 1,2
|
||||
)
|
||||
,province_to_audit (
|
||||
select
|
||||
PROVINCE_C
|
||||
,AUDIT_COD
|
||||
,DATA_SOURCE
|
||||
,CASE WHEN DATA_SOURCE = 'AIA(Monthly)' THEN 'AIA'
|
||||
WHEN DATA_SOURCE = 'IQVIA-CHPA(Monthly)' THEN 'CHPA'
|
||||
ELSE NULL
|
||||
END AS SOURCENAME
|
||||
from dm.dm_td_external_geo
|
||||
where DATA_SOURCE in ( 'AIA(Monthly)','IQVIA-CHPA(Monthly)')
|
||||
group by 1,2,3
|
||||
)
|
||||
,not_selected_datasource (--因为pack2market2pack 会导致部分大市场包含所有的pack,故用配置表再删除一些不需要配置数据源的
|
||||
select
|
||||
a.ims_pack_cod PACK_COD --取所有code
|
||||
,b.province
|
||||
from dwd.dwd_td_imscode_azcode a
|
||||
inner join (
|
||||
select
|
||||
UPPER(brand) as brand
|
||||
,province
|
||||
from brand_province_config
|
||||
where data_source = '/'
|
||||
group by 1,2
|
||||
) b
|
||||
on upper(a.brandnamee) = upper(b.brand )
|
||||
where a.ims_pack_cod is not null and startswith(a.ims_pack_cod,'0')
|
||||
group by 1,2
|
||||
union
|
||||
select
|
||||
pack_cod,
|
||||
'天津'
|
||||
from market_to_pack
|
||||
where market= 'EGFR TKI Market'
|
||||
group by 1
|
||||
)
|
||||
select DATA_SOURCE,PACK_COD,AUDIT_COD
|
||||
from not_selected_datasource a
|
||||
left join province_to_audit b on a.province = b.province_c
|
||||
group by 1,2,3
|
||||
|
||||
-- COMMAND ----------
|
||||
|
||||
INSERT OVERWRITE dws.dws_external_merge_data_config
|
||||
-- create or replace table dws.dws_external_merge_data_config
|
||||
/*
|
||||
1通过brand找到pack,通过pack找到市场以市场下的所有pack
|
||||
2通过province找到对应的省份或者机构,从而获取到audit_code
|
||||
*/
|
||||
----pack
|
||||
with pack_and_brand ( --brand 转 pack
|
||||
select
|
||||
upper(brandnamee) brand_name
|
||||
,ims_pack_cod PACK_COD --取所有code带出market
|
||||
from dwd.dwd_td_imscode_azcode
|
||||
where ims_pack_cod is not null and startswith(ims_pack_cod,'0')
|
||||
and upper(brandnamee) in (select brand from brand_province_config group by 1 )--取出在配置表中的pack
|
||||
group by 1,2
|
||||
)
|
||||
|
||||
,pack_to_market (
|
||||
select
|
||||
a.PACK_COD
|
||||
,MARKET
|
||||
from dm.dm_td_external_market_pack_mapping a
|
||||
inner join pack_and_brand b on a.PACK_COD = b.pack_cod --取出配置表中的brand对应的 market
|
||||
where DATA_SOURCE in ( 'AIA(Monthly)')--只取 AIA中的市场,chpa的市场太多
|
||||
and lower(a.MARKET) not like '%all market%'
|
||||
and market not in (
|
||||
'RE Extended Market'
|
||||
,'RE Market'
|
||||
,'RE Market (Global)'
|
||||
,'Pulmicort VBP Benchmark Market'
|
||||
,'Respules Market'
|
||||
)
|
||||
group by 1,2
|
||||
)
|
||||
,market_to_pack ( -- 获取上述market中所有的pack
|
||||
select
|
||||
market
|
||||
,pack_cod
|
||||
from dm.dm_td_external_market_pack_mapping a
|
||||
where DATA_SOURCE in ( 'AIA(Monthly)','IQVIA-CHPA(Monthly)')--AIA和chpa的市场
|
||||
and market in (select market from pack_to_market group by 1)
|
||||
group by 1,2
|
||||
)
|
||||
,province_to_audit (
|
||||
select
|
||||
PROVINCE_C
|
||||
,AUDIT_COD
|
||||
,DATA_SOURCE
|
||||
,CASE WHEN DATA_SOURCE = 'AIA(Monthly)' THEN 'AIA'
|
||||
WHEN DATA_SOURCE = 'IQVIA-CHPA(Monthly)' THEN 'CHPA'
|
||||
ELSE NULL
|
||||
END AS SOURCENAME
|
||||
from dm.dm_td_external_geo
|
||||
where DATA_SOURCE in ( 'AIA(Monthly)','IQVIA-CHPA(Monthly)')
|
||||
group by 1,2,3
|
||||
)
|
||||
|
||||
,pack_result as (
|
||||
select
|
||||
D.pack_cod
|
||||
,E.audit_cod
|
||||
,A.province
|
||||
,A.data_source as SOURCENAME
|
||||
,E.data_source
|
||||
from brand_province_config A
|
||||
inner join pack_and_brand B on A.brand = B.brand_name
|
||||
inner join pack_to_market C on B.pack_cod = C.pack_cod
|
||||
inner join market_to_pack D on C.market = D.market
|
||||
inner join province_to_audit E on A.province = E.province_c AND A.data_source = E.SOURCENAME
|
||||
where A.data_source <> '/'
|
||||
group by 1,2,3,4,5
|
||||
)
|
||||
|
||||
|
||||
----market
|
||||
,config_market (
|
||||
select
|
||||
market
|
||||
from market_province_config
|
||||
group by 1
|
||||
)
|
||||
,market_to_pack_dtp (
|
||||
select
|
||||
PACK_COD,MARKET
|
||||
from dm.dm_td_external_market_pack_mapping
|
||||
where DATA_SOURCE = 'DTP(Quarterly)' and PACK_COD in (
|
||||
select
|
||||
PACK_COD
|
||||
from dm.dm_tf_external_sales
|
||||
where DTP_FLAG =1
|
||||
group by 1)
|
||||
)
|
||||
,final_market_to_pack (--获取需要转换market成pack的部分
|
||||
select PACK_COD,a.MARKET from market_to_pack a inner join config_market b on a.market = b.market
|
||||
union
|
||||
select PACK_COD,a.MARKET from market_to_pack_dtp a inner join config_market b on a.market = b.market
|
||||
)
|
||||
|
||||
----market
|
||||
,market_result as (
|
||||
select
|
||||
B.pack_cod
|
||||
,C.AUDIT_COD
|
||||
,A.province
|
||||
,A.data_source as SOURCENAME
|
||||
,C.DATA_SOURCE
|
||||
from market_province_config a
|
||||
left join final_market_to_pack B on A.market = B.market
|
||||
left join province_to_audit C on A.province = C.province_c AND A.data_source = C.SOURCENAME
|
||||
where a.data_source <> '/' AND C.AUDIT_COD IS not NULL
|
||||
group by 1,2,3,4,5)
|
||||
,need_to_be_changed( --算出不在pack 中的pack code,替换成 market中的pack code 的配置信息
|
||||
select
|
||||
pack_cod,AUDIT_COD,DATA_SOURCE,sourcename
|
||||
from market_result
|
||||
where pack_cod in (select pack_cod from pack_result group by 1)
|
||||
)
|
||||
|
||||
--最终写入表
|
||||
|
||||
select
|
||||
pack_cod,AUDIT_COD,DATA_SOURCE,sourcename, 'pack' CONFIG_DATASOURCE
|
||||
from pack_result
|
||||
union ALL
|
||||
|
||||
select
|
||||
pack_cod,AUDIT_COD,DATA_SOURCE,sourcename, 'market' CONFIG_DATASOURCE
|
||||
from pack_result
|
||||
where pack_cod not in (select pack_cod from need_to_be_changed group by 1)
|
||||
union all
|
||||
select
|
||||
pack_cod,AUDIT_COD,DATA_SOURCE,sourcename, 'market' CONFIG_DATASOURCE
|
||||
from need_to_be_changed
|
||||
@@ -1,124 +0,0 @@
|
||||
-- Databricks notebook source
|
||||
-- create or replace table dm.dm_tf_exteranl_sales_merged_data_dtp_others
|
||||
insert overwrite table dm.dm_tf_exteranl_sales_merged_data_dtp_others
|
||||
with all_egfr_pack as (
|
||||
select * from DM.dm_td_external_market_pack_mapping
|
||||
where DATA_SOURCE = 'DTP(Quarterly)' and MARKET = 'EGFR TKI Market'
|
||||
)
|
||||
,4brand as (
|
||||
select * from all_egfr_pack
|
||||
where PROD_DES_C in ('阿美乐','泰瑞沙','凯美纳','艾弗沙')
|
||||
)
|
||||
,otherbrand as (
|
||||
select PACK_COD from all_egfr_pack
|
||||
where PACK_COD not in ( select PACK_COD from `4brand` group by 1)
|
||||
group by 1
|
||||
)
|
||||
|
||||
|
||||
-- -- 直取表 cu - dtp4brand 的 cu = otherbrand 的cu
|
||||
,dirct_cu as (
|
||||
select
|
||||
yyyymm
|
||||
,replace(audit_key,'DTP(Quarterly)','') audit_cod
|
||||
,cast(pdot_counting_unit as decimal ) pdot_counting_unit
|
||||
,cast(pdot_counting_unit_ly as decimal ) pdot_counting_unit_ly
|
||||
from dm.dm_tf_external_retail_special a
|
||||
where yyyymm >=202401
|
||||
)
|
||||
--先 4个brand 的 cu 和 value
|
||||
,fact_sales_dtp_4brand(
|
||||
select
|
||||
YYYYMM,AUDIT_COD
|
||||
,sum(cast( CONUTING_UNIT*PDOT_MARKET_RATIO as decimal)) CONUTING_UNIT
|
||||
,sum(cast( CONUTING_UNIT_LY*PDOT_MARKET_RATIO as decimal)) CONUTING_UNIT_LY
|
||||
from dm.dm_tf_external_sales t1
|
||||
inner join 4brand t2 on t1.PACK_COD = t2.PACK_COD
|
||||
where t1.DATA_SOURCE = 'DTP(Quarterly)'
|
||||
and DTP_FLAG = 1
|
||||
and YYYYMM >=202401
|
||||
group by
|
||||
YYYYMM,AUDIT_COD )
|
||||
|
||||
-- 其他产品 的 cu 和 value
|
||||
,fact_sales_dtp_other(
|
||||
select
|
||||
YYYYMM
|
||||
,"DTPOTHERS" PACK_COD
|
||||
,"DTPOTHERS" CORP_COD
|
||||
,AUDIT_COD
|
||||
,'' as PLATFORM_TYPE
|
||||
,'' as STORE_NAME
|
||||
,'' as STORE_TYPE
|
||||
,'' as REGION_TYPE
|
||||
,1 as PACK_FLAG
|
||||
,2 as PROD_FLAG
|
||||
,1 as DTP_FLAG
|
||||
,sum(SALES_UNIT_CAL) SALES_UNIT_CAL
|
||||
,sum(SALES_UNIT_CAL_LY) SALES_UNIT_CAL_LY
|
||||
,sum(SALES_VALUE_CAL) SALES_VALUE_CAL
|
||||
,sum(SALES_VALUE_CAL_LY) SALES_VALUE_CAL_LY
|
||||
,sum(CONUTING_UNIT) CONUTING_UNIT
|
||||
,sum(CONUTING_UNIT_LY) CONUTING_UNIT_LY
|
||||
,'DTP(Quarterly)' as DATA_SOURCE
|
||||
,'' as inst_code
|
||||
,'' as cmps_flag
|
||||
,'' as dept_name
|
||||
,'' as prescription
|
||||
,'' as prescription_ly
|
||||
,'' as new_code
|
||||
,'' as area
|
||||
,'' as h_level
|
||||
,'' as reimburse
|
||||
,'' as reimburse_type
|
||||
,'' as prescription_source
|
||||
from dm.dm_tf_external_sales
|
||||
where DTP_FLAG = 1
|
||||
and PACK_COD in (select PACK_COD from otherbrand) --其他部分
|
||||
and DATA_SOURCE = 'DTP(Quarterly)'
|
||||
and YYYYMM >=202401
|
||||
group by
|
||||
YYYYMM,AUDIT_COD)
|
||||
|
||||
select
|
||||
T0.YYYYMM
|
||||
,t0.PACK_COD
|
||||
,t0.CORP_COD
|
||||
,t0.AUDIT_COD
|
||||
,t0.PLATFORM_TYPE
|
||||
,t0.STORE_NAME
|
||||
,t0.STORE_TYPE
|
||||
,t0.REGION_TYPE
|
||||
,t0.PACK_FLAG
|
||||
,t0.PROD_FLAG
|
||||
,t0.DTP_FLAG
|
||||
,t0.SALES_UNIT_CAL
|
||||
,t0.SALES_UNIT_CAL_LY
|
||||
,t0.SALES_VALUE_CAL
|
||||
,t0.SALES_VALUE_CAL_LY
|
||||
,t1.CONUTING_UNIT
|
||||
,t1.CONUTING_UNIT_LY
|
||||
,t0.DATA_SOURCE
|
||||
,t0.inst_code
|
||||
,t0.cmps_flag
|
||||
,t0.dept_name
|
||||
,t0.prescription
|
||||
,t0.prescription_ly
|
||||
,t0.new_code
|
||||
,t0.area
|
||||
,t0.h_level
|
||||
,t0.reimburse
|
||||
,t0.reimburse_type
|
||||
,t0.prescription_source
|
||||
from fact_sales_dtp_other t0
|
||||
left join (
|
||||
select
|
||||
t1.yyyymm
|
||||
,t1.audit_cod
|
||||
,t1.pdot_counting_unit - t2.conuting_unit as CONUTING_UNIT
|
||||
,t1.pdot_counting_unit_ly - t2.conuting_unit_ly as CONUTING_UNIT_LY
|
||||
from dirct_cu t1
|
||||
left join fact_sales_dtp_4brand t2 on t1.yyyymm = t2.yyyymm and t1.audit_cod = t2.audit_cod
|
||||
) t1
|
||||
on t0.audit_cod = t1.audit_cod and t0.yyyymm = t1.yyyymm
|
||||
-- select * from fact_sales_dtp_4brand
|
||||
Reference in New Issue
Block a user