1820 lines
67 KiB
Plaintext
1820 lines
67 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"inputWidgets": {},
|
||
"nuid": "d61085b4-b83e-484e-bf7a-a2e0c1e69b6a",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- 有几张表发生了变化\n",
|
||
"-- tmp.tmp_ec_temp_market\n",
|
||
"-- tmp.tmp_ec_temp_market_del\n",
|
||
"-- dws.dws_zk_ec_pack_property\n",
|
||
"\n",
|
||
"-- dm.dm_zk_ec_market_ratio"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"finishTime": 1777013125396,
|
||
"inputWidgets": {},
|
||
"nuid": "0d9ce3a9-5ccb-48bc-a100-0d46e5e75bbf",
|
||
"showTitle": false,
|
||
"startTime": 1777013120348,
|
||
"submitTime": 1777013120175,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"insert overwrite table tmp.tmp_ec_temp_market\n",
|
||
"select distinct\n",
|
||
" b.iqvia_lineno ,\n",
|
||
" if( nvl(b.iqvia_pack_code,0) REGEXP '^[0-9]',right(concat('000000000000',nvl(b.iqvia_pack_code,0)),12),nvl(b.iqvia_pack_code,0)) as iqvia_pack_code,-- right(concat('0000000',nvl(b.iqvia_pack_code,0)),7)\n",
|
||
" right(concat('000000000',nvl(b.iqvia_prod_code,0)),9) as prod_cod ,-- right(concat('00000',nvl(b.iqvia_prod_code,0)),5)\n",
|
||
" b.iqvia_notes ,\n",
|
||
" b.new_pack_flag ,\n",
|
||
" b.is_exists_chpa ,\n",
|
||
" right(concat('0000000',nvl(b.product_id,0)),7) as product_id,\n",
|
||
" b.prescription_nature ,\n",
|
||
" b.medicine_type ,\n",
|
||
" b.zk_medicine_tier1 ,\n",
|
||
" b.zk_medicine_tier2 ,\n",
|
||
" b.zk_medicine_tier3 ,\n",
|
||
" b.zk_medicine_tier4 ,\n",
|
||
" b.common_name ,\n",
|
||
" b.dosage_form ,\n",
|
||
" b.user_type ,\n",
|
||
" b.category_name ,\n",
|
||
" b.product_name ,\n",
|
||
" b.brand_name ,\n",
|
||
" b.zk_manu_des ,\n",
|
||
" b.zk_corp_des ,\n",
|
||
" b.zk_pack_des ,\n",
|
||
" b.counting_unit_a ,\n",
|
||
" b.dosage_unit_a ,\n",
|
||
" b.unit_a ,\n",
|
||
" b.app1_cod ,\n",
|
||
" b.app1_des ,\n",
|
||
" b.app1_des_c ,\n",
|
||
" b.app2_cod ,\n",
|
||
" b.app2_des ,\n",
|
||
" b.app2_des_c ,\n",
|
||
" b.app3_cod ,\n",
|
||
" b.app3_des ,\n",
|
||
" b.app3_des_c ,\n",
|
||
" b.atc1_cod ,\n",
|
||
" b.atc1_des ,\n",
|
||
" b.atc1_des_c ,\n",
|
||
" b.atc2_cod ,\n",
|
||
" b.atc2_des ,\n",
|
||
" b.atc2_des_c ,\n",
|
||
" b.atc3_cod ,\n",
|
||
" b.atc3_des ,\n",
|
||
" b.atc3_des_c ,\n",
|
||
" b.atc4_cod ,\n",
|
||
" b.atc4_des ,\n",
|
||
" b.atc4_des_c ,\n",
|
||
" b.bio_desc ,\n",
|
||
" right(concat('000000',nvl(b.cmps_cod,0 )),6) cmps_cod,\n",
|
||
" b.cmps_des ,\n",
|
||
" b.cmps_des_c ,\n",
|
||
" b.corp_cod ,\n",
|
||
" b.corp_des ,\n",
|
||
" b.corp_des_c ,\n",
|
||
" b.edl_desc ,\n",
|
||
" b.eth_otc_desc ,\n",
|
||
" b.gene_orig_desc ,\n",
|
||
" b.gqce_desc ,\n",
|
||
" b.manu_cod ,\n",
|
||
" b.manu_des ,\n",
|
||
" b.manu_des_c ,\n",
|
||
" b.mnfl_cod ,\n",
|
||
" b.mnfl_des ,\n",
|
||
" b.nrdl_desc ,\n",
|
||
" b.pack_des ,\n",
|
||
" b.stgh_des ,\n",
|
||
" b.pack_lch ,\n",
|
||
" b.paed_desc ,\n",
|
||
" b.prod_des ,\n",
|
||
" b.prod_des_c ,\n",
|
||
" b.tcm_desc ,\n",
|
||
" b.vbp_desc ,\n",
|
||
" b.unit ,\n",
|
||
" b.counting_unit ,\n",
|
||
" b.dosage_unit ,\n",
|
||
"\tnvl(mole.NRDL_Entry_Date,'') as NRDL_ENTRY_DATE,\n",
|
||
"\ttblmkt.Market,\n",
|
||
"\ttblmkt.bu,\n",
|
||
"\tnvl(tblmkt.extend_market_ratio,1) as extend_market_ratio,\n",
|
||
"\t-- c.ta,\n",
|
||
"\tif(b.corp_des_c in ('阿斯利康制药集团'),'Y','N') as is_az\n",
|
||
"from dwd.dwd_gnd_ext_retail_pack_property as b\n",
|
||
"left join dwd.dwd_ims_td_pack_additional_attribute mole on b.iqvia_pack_code = mole.Pack_Code\n",
|
||
"left join (\n",
|
||
" select\n",
|
||
"\t\tmarket,bu,atc1_code,atc2_code,atc3_code,atc4_code,nfc1_code,nfc2_code,nfc3_code,pack_code,pack_desc,strength,product_code,product_desc,molecule_code,molecule_desc,not_in_flag,extend_market,extend_market_ratio,corporation_code,corporation_desc,manufacturer_code,manufacturer_desc,zk_common_name,zk_product_id,zk_dosage_form\n",
|
||
" from dwd.dwd_gnd_ec_retail_tblmarket_rule\n",
|
||
"\twhere extend_market is null and ( NOT_IN_FLAG IS NULL or NOT_IN_FLAG = '1' )\n",
|
||
") tblmkt\n",
|
||
"on \t COALESCE(b.ATC1_COD,'') = case when tblmkt.ATC1_Code is null then COALESCE(b.ATC1_COD,'')\telse tblmkt.ATC1_Code end\n",
|
||
"\t\tand COALESCE(b.ATC2_COD,'') = case when tblmkt.ATC2_Code is null then COALESCE(b.ATC2_COD,'')\telse tblmkt.ATC2_Code end\n",
|
||
"\t\tand COALESCE(b.ATC3_COD,'') = case when tblmkt.ATC3_Code is null then COALESCE(b.ATC3_COD,'')\telse tblmkt.ATC3_Code end\n",
|
||
"\t\tand COALESCE(b.ATC4_COD,'') = case when tblmkt.ATC4_Code is null then COALESCE(b.ATC4_COD,'')\telse tblmkt.ATC4_Code end\n",
|
||
"\t\tand COALESCE(b.APP1_COD,'') = case when tblmkt.NFC1_Code is null then COALESCE(b.APP1_COD,'')\telse tblmkt.NFC1_Code end\n",
|
||
"\t\tand COALESCE(b.APP2_COD,'') = case when tblmkt.NFC2_Code is null then COALESCE(b.APP2_COD,'')\telse tblmkt.NFC2_Code end\n",
|
||
"\t\tand COALESCE(b.app3_cod,'') = case when tblmkt.NFC3_Code is null then COALESCE(b.app3_cod,'')\telse tblmkt.NFC3_Code end\n",
|
||
"\t\tand COALESCE(b.stgh_des,'') = case when tblmkt.Strength is null then COALESCE(b.stgh_des,'') else tblmkt.Strength end\n",
|
||
"\t\tand COALESCE(b.corp_cod,'') = case when tblmkt.Corporation_Code is null then COALESCE(b.corp_cod,'') else tblmkt.Corporation_Code end\n",
|
||
"\t\tand COALESCE(b.manu_cod,'') = case when tblmkt.Manufacturer_Code is null then COALESCE(b.manu_cod,'') else tblmkt.Manufacturer_Code end\n",
|
||
"\t and right(concat('0000000',nvl(b.product_id,0)),7 ) = case when tblmkt.zk_product_id is null then right(concat('0000000',nvl(b.product_id,0) ),7 ) else right(concat('0000000',tblmkt.zk_product_id),7) end\n",
|
||
"\t\tand right(concat('000000000',COALESCE(b.iqvia_prod_code,0)),9) = case when tblmkt.Product_Code is null then right(concat('000000000',COALESCE(b.iqvia_prod_code,0)),9) else right(concat('000000000', tblmkt.Product_Code),9) end\n",
|
||
" -- and right(concat('00000',COALESCE(b.iqvia_prod_code,0)),5) = case when tblmkt.Product_Code is null then right(concat('00000',COALESCE(b.iqvia_prod_code,0)),5) else right(concat('00000', tblmkt.Product_Code),5) end\n",
|
||
"\t\tand if(COALESCE(b.iqvia_pack_code,0) REGEXP '^[0-9]',right(concat('000000000000',COALESCE(b.iqvia_pack_code,0)),12),COALESCE(b.iqvia_pack_code,0)) = case when tblmkt.Pack_Code \t is null then if(COALESCE(b.iqvia_pack_code,0) REGEXP '^[0-9]' ,right(concat('000000000000',COALESCE(b.iqvia_pack_code,0)),12),COALESCE(b.iqvia_pack_code,0)) else if( tblmkt.Pack_Code REGEXP '^[0-9]', right(concat('000000000000',tblmkt.Pack_Code),12),tblmkt.Pack_Code) end\n",
|
||
"\t\t-- and right(concat('0000000',COALESCE(b.iqvia_pack_code,0)),7) = case when tblmkt.Pack_Code \t is null then right(concat('0000000',COALESCE(b.iqvia_pack_code,0)),7) else right(concat('0000000',tblmkt.Pack_Code),7) end\n",
|
||
"\t\tand right(concat('000000',COALESCE(b.CMPS_COD,0)),6) \t= case when tblmkt.Molecule_Code \t is null then right(concat('000000',COALESCE(b.CMPS_COD,0)),6) else right(concat('000000',tblmkt.Molecule_Code),6) end\n",
|
||
"-- left join dwd.dwd_gnd_ext_retail_dim_ta c\n",
|
||
"-- on c.market = tblmkt.Market\n",
|
||
"where tblmkt.market is not null ;\n",
|
||
"insert overwrite table tmp.tmp_ec_temp_market_del\n",
|
||
"select\n",
|
||
" b.iqvia_lineno ,\n",
|
||
" if( nvl(b.iqvia_pack_code,0) REGEXP '^[0-9]',right(concat('000000000000',nvl(b.iqvia_pack_code,0)),12),nvl(b.iqvia_pack_code,0)) as iqvia_pack_code,-- right(concat('0000000',nvl(b.iqvia_pack_code,0)),7)\n",
|
||
" right(concat('000000000',nvl(b.iqvia_prod_code,0)),9) as prod_cod ,-- right(concat('00000',nvl(b.iqvia_prod_code,0)),5)\n",
|
||
" b.iqvia_notes ,\n",
|
||
" b.new_pack_flag ,\n",
|
||
" b.is_exists_chpa ,\n",
|
||
" right(concat('0000000',nvl(b.product_id,0)),7) as product_id,\n",
|
||
" b.prescription_nature ,\n",
|
||
" b.medicine_type ,\n",
|
||
" b.zk_medicine_tier1 ,\n",
|
||
" b.zk_medicine_tier2 ,\n",
|
||
" b.zk_medicine_tier3 ,\n",
|
||
" b.zk_medicine_tier4 ,\n",
|
||
" b.common_name ,\n",
|
||
" b.dosage_form ,\n",
|
||
" b.user_type ,\n",
|
||
" b.category_name ,\n",
|
||
" b.product_name ,\n",
|
||
" b.brand_name ,\n",
|
||
" b.zk_manu_des ,\n",
|
||
" b.zk_corp_des ,\n",
|
||
" b.zk_pack_des ,\n",
|
||
" b.counting_unit_a ,\n",
|
||
" b.dosage_unit_a ,\n",
|
||
" b.unit_a ,\n",
|
||
" b.app1_cod ,\n",
|
||
" b.app1_des ,\n",
|
||
" b.app1_des_c ,\n",
|
||
" b.app2_cod ,\n",
|
||
" b.app2_des ,\n",
|
||
" b.app2_des_c ,\n",
|
||
" b.app3_cod ,\n",
|
||
" b.app3_des ,\n",
|
||
" b.app3_des_c ,\n",
|
||
" b.atc1_cod ,\n",
|
||
" b.atc1_des ,\n",
|
||
" b.atc1_des_c ,\n",
|
||
" b.atc2_cod ,\n",
|
||
" b.atc2_des ,\n",
|
||
" b.atc2_des_c ,\n",
|
||
" b.atc3_cod ,\n",
|
||
" b.atc3_des ,\n",
|
||
" b.atc3_des_c ,\n",
|
||
" b.atc4_cod ,\n",
|
||
" b.atc4_des ,\n",
|
||
" b.atc4_des_c ,\n",
|
||
" b.bio_desc ,\n",
|
||
" right(concat('000000',nvl(b.cmps_cod,0 )),6) cmps_cod,\n",
|
||
" b.cmps_des ,\n",
|
||
" b.cmps_des_c ,\n",
|
||
" b.corp_cod ,\n",
|
||
" b.corp_des ,\n",
|
||
" b.corp_des_c ,\n",
|
||
" b.edl_desc ,\n",
|
||
" b.eth_otc_desc ,\n",
|
||
" b.gene_orig_desc ,\n",
|
||
" b.gqce_desc ,\n",
|
||
" b.manu_cod ,\n",
|
||
" b.manu_des ,\n",
|
||
" b.manu_des_c ,\n",
|
||
" b.mnfl_cod ,\n",
|
||
" b.mnfl_des ,\n",
|
||
" b.nrdl_desc ,\n",
|
||
" b.pack_des ,\n",
|
||
" b.stgh_des ,\n",
|
||
" b.pack_lch ,\n",
|
||
" b.paed_desc ,\n",
|
||
" b.prod_des ,\n",
|
||
" b.prod_des_c ,\n",
|
||
" b.tcm_desc ,\n",
|
||
" b.vbp_desc ,\n",
|
||
" b.unit ,\n",
|
||
" b.counting_unit ,\n",
|
||
" b.dosage_unit ,\n",
|
||
"\tnvl(mole.NRDL_Entry_Date,'') as NRDL_ENTRY_DATE,\n",
|
||
"\ttblmkt.Market,\n",
|
||
"\ttblmkt.bu,\n",
|
||
"\tnvl(tblmkt.extend_market_ratio,1) as extend_market_ratio,\n",
|
||
"\t-- c.ta,\n",
|
||
"\tif(b.corp_des_c in ('阿斯利康制药集团'),'Y','N') as is_az\n",
|
||
"from dwd.dwd_gnd_ext_retail_pack_property as b\n",
|
||
"left join dwd.dwd_ims_td_pack_additional_attribute mole on b.iqvia_pack_code = mole.Pack_Code\n",
|
||
"left join (\n",
|
||
" select\n",
|
||
"\t\tmarket,bu,atc1_code,atc2_code,atc3_code,atc4_code,nfc1_code,nfc2_code,nfc3_code,pack_code,pack_desc,strength,product_code,product_desc,molecule_code,molecule_desc,not_in_flag,extend_market,extend_market_ratio,corporation_code,corporation_desc,manufacturer_code,manufacturer_desc,zk_common_name,zk_product_id,zk_dosage_form\n",
|
||
" from dwd.dwd_gnd_ec_retail_tblmarket_rule\n",
|
||
"\twhere Extend_Market is null and NOT_IN_FLAG = '0'\n",
|
||
") tblmkt\n",
|
||
"on \t COALESCE(b.ATC1_COD,'') = case when tblmkt.ATC1_Code is null then COALESCE(b.ATC1_COD,'')\telse tblmkt.ATC1_Code end\n",
|
||
"\t\tand COALESCE(b.ATC2_COD,'') = case when tblmkt.ATC2_Code is null then COALESCE(b.ATC2_COD,'')\telse tblmkt.ATC2_Code end\n",
|
||
"\t\tand COALESCE(b.ATC3_COD,'') = case when tblmkt.ATC3_Code is null then COALESCE(b.ATC3_COD,'')\telse tblmkt.ATC3_Code end\n",
|
||
"\t\tand COALESCE(b.ATC4_COD,'') = case when tblmkt.ATC4_Code is null then COALESCE(b.ATC4_COD,'')\telse tblmkt.ATC4_Code end\n",
|
||
"\t\tand COALESCE(b.APP1_COD,'') = case when tblmkt.NFC1_Code is null then COALESCE(b.APP1_COD,'')\telse tblmkt.NFC1_Code end\n",
|
||
"\t\tand COALESCE(b.APP2_COD,'') = case when tblmkt.NFC2_Code is null then COALESCE(b.APP2_COD,'')\telse tblmkt.NFC2_Code end\n",
|
||
"\t\tand COALESCE(b.app3_cod,'') = case when tblmkt.NFC3_Code is null then COALESCE(b.app3_cod,'')\telse tblmkt.NFC3_Code end\n",
|
||
"\t\tand COALESCE(b.stgh_des,'') = case when tblmkt.Strength is null then COALESCE(b.stgh_des,'') else tblmkt.Strength end\n",
|
||
"\t\tand COALESCE(b.corp_cod,'') = case when tblmkt.Corporation_Code is null then COALESCE(b.corp_cod,'') else tblmkt.Corporation_Code end\n",
|
||
"\t\tand COALESCE(b.manu_cod,'') = case when tblmkt.Manufacturer_Code is null then COALESCE(b.manu_cod,'') else tblmkt.Manufacturer_Code end\n",
|
||
"\t and right(concat('0000000',nvl(b.product_id,0)),7 ) = case when tblmkt.zk_product_id is null then right(concat('0000000',nvl(b.product_id,0) ),7 ) else right(concat('0000000',tblmkt.zk_product_id),7) end\n",
|
||
"\t\tand right(concat('000000000',COALESCE(b.iqvia_prod_code,0)),9) = case when tblmkt.Product_Code is null then right(concat('000000000',COALESCE(b.iqvia_prod_code,0)),9) else right(concat('000000000', tblmkt.Product_Code),9) end\n",
|
||
" -- and right(concat('00000',COALESCE(b.iqvia_prod_code,0)),5) = case when tblmkt.Product_Code is null then right(concat('00000',COALESCE(b.iqvia_prod_code,0)),5) else right(concat('00000', tblmkt.Product_Code),5) end\n",
|
||
"\t\tand if(COALESCE(b.iqvia_pack_code,0) REGEXP '^[0-9]',right(concat('000000000000',COALESCE(b.iqvia_pack_code,0)),12),COALESCE(b.iqvia_pack_code,0)) = case when tblmkt.Pack_Code \t is null then if(COALESCE(b.iqvia_pack_code,0) REGEXP '^[0-9]' ,right(concat('000000000000',COALESCE(b.iqvia_pack_code,0)),12),COALESCE(b.iqvia_pack_code,0)) else if( tblmkt.Pack_Code REGEXP '^[0-9]', right(concat('000000000000',tblmkt.Pack_Code),12),tblmkt.Pack_Code) end\n",
|
||
"\t\t-- and right(concat('0000000',COALESCE(b.iqvia_pack_code,0)),7) = case when tblmkt.Pack_Code \t is null then right(concat('0000000',COALESCE(b.iqvia_pack_code,0)),7) else right(concat('0000000',tblmkt.Pack_Code),7) end\n",
|
||
"\t\tand right(concat('000000',COALESCE(b.CMPS_COD,0)),6) \t= case when tblmkt.Molecule_Code \t is null then right(concat('000000',COALESCE(b.CMPS_COD,0)),6) else right(concat('000000',tblmkt.Molecule_Code),6) end\n",
|
||
"-- left join dwd.dwd_gnd_ext_retail_dim_ta c\n",
|
||
"-- on c.market = tblmkt.Market\n",
|
||
"where tblmkt.market is not null ;\n",
|
||
"\n",
|
||
"MERGE INTO tmp.tmp_ec_temp_market AS t1\n",
|
||
"USING tmp.tmp_ec_temp_market_del AS t2\n",
|
||
"\t on COALESCE(t1.ATC1_COD,'') = COALESCE(t2.ATC1_COD,'')\n",
|
||
" and COALESCE(t1.ATC2_COD,'') = COALESCE(t2.ATC2_COD,'')\n",
|
||
" and COALESCE(t1.ATC3_COD,'') = COALESCE(t2.ATC3_COD,'')\n",
|
||
" and COALESCE(t1.ATC4_COD,'') = COALESCE(t2.ATC4_COD,'')\n",
|
||
" and COALESCE(t1.APP1_COD,'') = COALESCE(t2.APP1_COD,'')\n",
|
||
" and COALESCE(t1.APP2_COD,'') = COALESCE(t2.APP2_COD,'')\n",
|
||
" and COALESCE(t1.APP3_COD,'') = COALESCE(t2.APP3_COD,'')\n",
|
||
" and COALESCE(t1.CORP_COD,'') = COALESCE(t2.CORP_COD,'')\n",
|
||
" and COALESCE(t1.MANU_COD,'') = COALESCE(t2.MANU_COD,'')\n",
|
||
" and COALESCE(t1.PROD_COD,'') = COALESCE(t2.PROD_COD,'')\n",
|
||
" and COALESCE(t1.iqvia_pack_code,'') = COALESCE(t2.iqvia_pack_code,'')\n",
|
||
" and COALESCE(t1.STGH_DES,'') = COALESCE(t2.STGH_DES,'')\n",
|
||
" and COALESCE(t1.CMPS_COD,'') = COALESCE(t2.CMPS_COD,'')\n",
|
||
" and COALESCE(t1.market,'') = COALESCE(t2.market,'')\n",
|
||
"WHEN MATCHED THEN DELETE ;\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"inputWidgets": {},
|
||
"nuid": "f0391d63-baaa-4748-9285-b15ab11d1b2b",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"--处理 Extend_Market 有值得数据,用已有市场,定义新的市场,带上系数\n",
|
||
"insert into tmp.tmp_ec_temp_market\n",
|
||
"select\n",
|
||
"iqvia_lineno,iqvia_pack_code,prod_cod,iqvia_notes,new_pack_flag,is_exists_chpa,product_id,prescription_nature,medicine_type,zk_medicine_tier1,zk_medicine_tier2,zk_medicine_tier3,zk_medicine_tier4,common_name,dosage_form,user_type,category_name,product_name,brand_name,zk_manu_des,zk_corp_des,zk_pack_des,counting_unit_a,dosage_unit_a,unit_a,app1_cod,app1_des,app1_des_c,app2_cod,app2_des,app2_des_c,app3_cod,app3_des,app3_des_c,atc1_cod,atc1_des,atc1_des_c,atc2_cod,atc2_des,atc2_des_c,atc3_cod,atc3_des,atc3_des_c,atc4_cod,atc4_des,atc4_des_c,bio_desc,cmps_cod,cmps_des,cmps_des_c,corp_cod,corp_des,corp_des_c,edl_desc,eth_otc_desc,gene_orig_desc,gqce_desc,manu_cod,manu_des,manu_des_c,mnfl_cod,mnfl_des,nrdl_desc,pack_des,stgh_des,pack_lch,paed_desc,prod_des,prod_des_c,tcm_desc,vbp_desc,unit,counting_unit,dosage_unit,NRDL_ENTRY_DATE,t2.Market,t2.bu,nvl(t2.extend_market_ratio,1) as extend_market_ratio,is_az\n",
|
||
"from tmp.tmp_ec_temp_market t1\n",
|
||
"left join (select Market,BU,Extend_Market,Extend_Market_Ratio from dwd.dwd_gnd_ec_retail_tblmarket_rule where Extend_Market is not null )t2\n",
|
||
"on t1.Market = t2.Extend_Market\n",
|
||
"where t2.Market is not null"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "4c6fff68-ab10-4620-bcb4-296d51e992e6",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-----------事实表数据处理:获取counting_unit字段,给特殊字段补0,并对数据去重(QTD粒度)\n",
|
||
"insert overwrite table tmp.tmp_ec_source\n",
|
||
"select\n",
|
||
" concat(year(a.time), 'Q', quarter(a.time)) as ytd,\n",
|
||
" right(concat('0000000',a.product_id),7) as pack_id,\n",
|
||
" if( b.iqvia_pack_code REGEXP '^[0-9]',right(concat('000000000000',b.iqvia_pack_code),12),b.iqvia_pack_code) as iqvia_pack_code,\n",
|
||
" a.platform,\n",
|
||
" a.store_name,\n",
|
||
" a.store_type,\n",
|
||
" sum(a.sales_amount) as sales_value,\n",
|
||
" sum(a.sales_qty) as sales_unit,\n",
|
||
" cast(sum(a.sales_qty*(b.counting_unit/coalesce(unit,1 ))) as decimal(30,10)) as counting_unit\n",
|
||
"from dwd.dwd_inc_gnd_ext_ec_nationnal_pack_union_all a\n",
|
||
"left join (\n",
|
||
" select DISTINCT product_id,iqvia_pack_code,counting_unit,unit,prod_des_c\n",
|
||
" from dwd.dwd_gnd_ext_retail_pack_property) b\n",
|
||
"on right(concat('0000000',a.product_id),7) = right(concat('0000000',b.product_id),7)\n",
|
||
"group by\n",
|
||
" concat(year(a.time), 'Q', quarter(a.time)),\n",
|
||
" right(concat('0000000',a.product_id),7)\n",
|
||
" ,if( b.iqvia_pack_code REGEXP '^[0-9]',right(concat('000000000000',b.iqvia_pack_code),12),b.iqvia_pack_code)\n",
|
||
" ,a.platform,a.store_name\n",
|
||
" ,a.store_type"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "1c5f831b-111b-443a-9d87-bed1a7fca68f",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"insert overwrite table dws.dws_zk_ec_sales\n",
|
||
"select\n",
|
||
" t1.ytd,t1.pack_id,t1.iqvia_pack_code,t1.platform,t1.store_name,t1.store_type,\n",
|
||
" sum(sales_value) as sales_value,\n",
|
||
" sum(sales_unit) as sales_unit,\n",
|
||
" sum(counting_unit) as counting_unit\n",
|
||
"from tmp.tmp_ec_source t1\n",
|
||
"group by\n",
|
||
" t1.ytd,t1.pack_id,t1.iqvia_pack_code,t1.platform,t1.store_name,t1.store_type"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "4468f90b-48aa-4e4e-9b13-401a34f35956",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- -------------------------处理top_ta_corp数据\n",
|
||
"-- insert overwrite table dws.dws_zk_ec_by_ta_top_corp\n",
|
||
"-- select\n",
|
||
"-- t1.yyyymm,\n",
|
||
"-- t1.ta,\n",
|
||
"-- t1.rank,\n",
|
||
"-- t1.corp_des,\n",
|
||
"-- t1.CORP_COD,\n",
|
||
"-- t1.platform,\n",
|
||
"-- t1.store_type,\n",
|
||
"-- sum(t1.sales_value) sales_value\n",
|
||
"-- from (\n",
|
||
"-- select\n",
|
||
"-- a.ytd yyyymm,\n",
|
||
"-- a.ta,\n",
|
||
"-- a.rank,\n",
|
||
"-- a.corp_des,\n",
|
||
"-- b.CORP_COD,\n",
|
||
"-- a.platform,\n",
|
||
"-- a.store_type,\n",
|
||
"-- replace(a.sales_value,',','') as sales_value\n",
|
||
"-- from dwd.dwd_gnd_ec_ta_overview a\n",
|
||
"-- left join (select distinct ZK_Corp_C ,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total) b\n",
|
||
"-- on b.ZK_Corp_C = a.corp_des\n",
|
||
"-- ) t1\n",
|
||
"-- group by 1,2,3,4,5,6,7"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "65fd3cdb-0424-499e-9621-5de159c31455",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- -----加工倒减的by_corp_by_ta_by_total表数据,获取去年数据\n",
|
||
"-- insert overwrite table dws.dws_zk_ec_by_ta_top_corp\n",
|
||
"-- select\n",
|
||
"-- t1.yyyymm,\n",
|
||
"-- t1.ta,\n",
|
||
"-- t1.rank,\n",
|
||
"-- t1.corp_des,\n",
|
||
"-- t1.CORP_COD,\n",
|
||
"-- t1.platform,\n",
|
||
"-- t1.store_type,\n",
|
||
"-- sum(t1.sales_value) sales_value\n",
|
||
"-- from(\n",
|
||
"-- select\n",
|
||
"-- a.ytd yyyymm,\n",
|
||
"-- a.ta,\n",
|
||
"-- a.rank,\n",
|
||
"-- a.corp_des,\n",
|
||
"-- b.CORP_COD,\n",
|
||
"-- a.platform,\n",
|
||
"-- a.store_type,\n",
|
||
"-- replace(a.sales_value,',','') as sales_value\n",
|
||
"-- from dwd.dwd_gnd_ec_ta_overview a\n",
|
||
"-- left join (select distinct ZK_Corp_C ,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total) b\n",
|
||
"-- on b.ZK_Corp_C = a.corp_des\n",
|
||
"-- )t1\n",
|
||
"-- group by 1,2,3,4,5,6,7"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "b55d8e37-aca4-4a45-838d-7304be5caccf",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- ----倒减需要用到公司信息以及ta信息,加工配置表挂靠Corp、ta\n",
|
||
"-- insert overwrite table tmp.tmp_zk_ec_pack_property_corp\n",
|
||
"-- select distinct a.product_id,a.iqvia_pack_code,a.Market,ta.ta\n",
|
||
"-- ,COALESCE(c.corp_cod,b.corp_cod,a.corp_cod) corp_cod\n",
|
||
"-- ,COALESCE(c.corp_des,b.corp_des,a.corp_des) corp_des\n",
|
||
"-- ,COALESCE(d.corp_des_c,a.corp_des_c ) corp_des_c\n",
|
||
"-- ,COALESCE(c.manu_cod,b.manu_cod,a.manu_cod) manu_cod\n",
|
||
"-- ,COALESCE(c.manu_des,b.manu_des,a.manu_des) manu_des\n",
|
||
"-- ,COALESCE(e.manu_des_c,a.manu_des_c) manu_des_c\n",
|
||
"-- from (select DISTINCT product_id,iqvia_pack_code,Market,corp_cod,corp_des,corp_des_c,manu_cod,manu_des,manu_des_c,prod_cod from tmp.tmp_ec_temp_market) a\n",
|
||
"-- left join dwd.dwd_gnd_ext_retail_dim_ta ta\n",
|
||
"-- on a.Market = ta.market\n",
|
||
"-- left join (select right(concat('000000000',prod_cod ),9) prod_cod,corp_cod,corp_des,manu_cod,manu_des from dwd.dwd_gnd_tbl_corp_change where pack_cod is null ) b\n",
|
||
"-- on right(concat('000000000',A.prod_cod ),9)= b.prod_cod\n",
|
||
"-- left join (select if( pack_cod REGEXP '^[0-9]',right(concat('000000000000',pack_cod),12),pack_cod) pack_cod,corp_cod,corp_des,manu_cod,manu_des from dwd.dwd_gnd_tbl_corp_change where pack_cod is not null ) c\n",
|
||
"-- on a.iqvia_pack_code = c.pack_cod\n",
|
||
"-- left join (select distinct corp_cod,corp_des_c from dwd.dwd_gnd_ext_retail_pack_property) d\n",
|
||
"-- on coalesce(C.corp_cod,B.corp_cod ) = d.corp_cod\n",
|
||
"-- Left join (select distinct manu_cod,manu_des,manu_des_c from dwd.dwd_gnd_ext_retail_pack_property) e\n",
|
||
"-- On coalesce(C.manu_cod,B.manu_cod ) = e.manu_cod"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "aef61309-7acf-4a2f-a7af-669027a496fd",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- -------------------------------------------------------ec倒减-------------------------------------------------------\n",
|
||
"-- --注意事项:\n",
|
||
"-- -- 只做了CV、CVRM、TA大数的倒减,其余TA没有做\n",
|
||
"-- --cv倒减:关联加工好的配置表,获取ta信息进行倒减\n",
|
||
"-- insert overwrite table tmp.tmp_dm_zk_ec_sales_cv_tmp\n",
|
||
"-- with cv_data as (\n",
|
||
"-- select\n",
|
||
"-- t1.yyyymm,\n",
|
||
"-- t1.pack_id,\n",
|
||
"-- t1.iqvia_pack_code,\n",
|
||
"-- t1.platform,\n",
|
||
"-- t1.store_type,\n",
|
||
"-- t1.store_name,\n",
|
||
"-- t1.sales_value,\n",
|
||
"-- t1.sales_unit,\n",
|
||
"-- t1.counting_unit,\n",
|
||
"-- max(t2.ta) ta\n",
|
||
"-- from dws.dws_zk_ec_sales t1\n",
|
||
"-- left join (select distinct iqvia_pack_code,ta from tmp.tmp_zk_ec_pack_property_corp) t2\n",
|
||
"-- on t1.iqvia_pack_code = t2.iqvia_pack_code\n",
|
||
"-- where t2.ta = 'CV'\n",
|
||
"-- group by 1,2,3,4,5,6,7,8,9\n",
|
||
"-- ),cv_corp_data as (\n",
|
||
"-- -----------------------cv下的az 数据\n",
|
||
"-- select\n",
|
||
"-- A.yyyymm,\n",
|
||
"-- A.pack_id,\n",
|
||
"-- A.iqvia_pack_code,\n",
|
||
"-- A.platform,\n",
|
||
"-- A.store_type,\n",
|
||
"-- A.store_name,\n",
|
||
"-- B.corp_cod,\n",
|
||
"-- A.sales_value,\n",
|
||
"-- A.sales_unit,\n",
|
||
"-- A.counting_unit,\n",
|
||
"-- A.ta\n",
|
||
"-- from cv_data A\n",
|
||
"-- inner join(select distinct iqvia_pack_code,corp_cod,product_id from tmp.tmp_zk_ec_pack_property_corp) B\n",
|
||
"-- on A.pack_id = B.product_id\n",
|
||
"-- where B.corp_cod = 'A5Z'\n",
|
||
"-- union all\n",
|
||
"-- -----------------------cv下的az others数据\n",
|
||
"-- select\n",
|
||
"-- cv_az.yyyymm,\n",
|
||
"-- 'CV_AZ_OTHERS' as pack_id,\n",
|
||
"-- 'CV_AZ_OTHERS' as iqvia_pack_code,\n",
|
||
"-- cv_az.platform,\n",
|
||
"-- cv_az.store_type,\n",
|
||
"-- case when cv_az.store_type = '自营旗舰' then 'CV_AZ_OTHERS_SO' when cv_az.store_type = '第三方' then 'CV_AZ_OTHERS_POP' end store_name,\n",
|
||
"-- cv_az.corp_cod,\n",
|
||
"-- cv_az_total.sales_value - cv_az.sales_value as sales_value,\n",
|
||
"-- 0,0,\n",
|
||
"-- 'CV_AZ_OTHERS' as ta\n",
|
||
"-- from (\n",
|
||
"-- select\n",
|
||
"-- A.yyyymm,\n",
|
||
"-- B.corp_cod,\n",
|
||
"-- A.platform,\n",
|
||
"-- case when A.store_type = '平台店' or A.store_type = '品牌店' then '自营旗舰' else A.store_type end store_type,\n",
|
||
"-- sum(A.sales_value) sales_value\n",
|
||
"-- from cv_data A\n",
|
||
"-- inner join(select distinct iqvia_pack_code,corp_cod,product_id from tmp.tmp_zk_ec_pack_property_corp) B\n",
|
||
"-- on A.pack_id = B.product_id\n",
|
||
"-- where B.corp_cod = 'A5Z'\n",
|
||
"-- group by 1,2,3,4\n",
|
||
"-- )cv_az\n",
|
||
"-- left join(\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- CORP_COD,\n",
|
||
"-- platform,\n",
|
||
"-- case when store_type = '三方' then '第三方' else store_type end store_type,\n",
|
||
"-- sum(sales_value) sales_value\n",
|
||
"-- from dws.dws_zk_ec_by_ta_top_corp\n",
|
||
"-- where ta = 'CV' and CORP_COD = 'A5Z'\n",
|
||
"-- group by 1,2,3,4\n",
|
||
"-- )cv_az_total\n",
|
||
"-- on cv_az.yyyymm = cv_az_total.yyyymm\n",
|
||
"-- and cv_az.corp_cod = cv_az_total.CORP_COD\n",
|
||
"-- and cv_az.platform = cv_az_total.platform\n",
|
||
"-- and cv_az.store_type = cv_az_total.store_type\n",
|
||
"-- union all\n",
|
||
"-- ---------------cv下的非az数据\n",
|
||
"-- select\n",
|
||
"-- A.yyyymm,\n",
|
||
"-- A.pack_id,\n",
|
||
"-- A.iqvia_pack_code,\n",
|
||
"-- A.platform,\n",
|
||
"-- A.store_type,\n",
|
||
"-- A.store_name,\n",
|
||
"-- B.corp_cod,\n",
|
||
"-- A.sales_value,\n",
|
||
"-- A.sales_unit,\n",
|
||
"-- A.counting_unit,\n",
|
||
"-- A.ta\n",
|
||
"-- from cv_data A\n",
|
||
"-- inner join(select distinct iqvia_pack_code,corp_cod,product_id from tmp.tmp_zk_ec_pack_property_corp) B\n",
|
||
"-- on A.pack_id = B.product_id\n",
|
||
"-- where nvl(corp_cod,'') <>'A5Z'\n",
|
||
"-- )\n",
|
||
"-- -----------------------所有cv 数据\n",
|
||
"-- ,all_cv_data as (\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- pack_id,\n",
|
||
"-- iqvia_pack_code,\n",
|
||
"-- platform,\n",
|
||
"-- store_type,\n",
|
||
"-- store_name,\n",
|
||
"-- corp_cod,\n",
|
||
"-- sales_value,\n",
|
||
"-- sales_unit,\n",
|
||
"-- counting_unit,\n",
|
||
"-- 'CV' flag,\n",
|
||
"-- ta\n",
|
||
"-- from cv_corp_data\n",
|
||
"-- union all\n",
|
||
"-- -----------------------倒减出cv_others数据\n",
|
||
"-- select\n",
|
||
"-- t1.yyyymm,\n",
|
||
"-- 'CV_OTHERS' as pack_id,\n",
|
||
"-- 'CV_OTHERS' as iqvia_pack_code,\n",
|
||
"-- t1.platform,\n",
|
||
"-- t1.store_type,\n",
|
||
"-- case when t1.store_type = '自营旗舰' then 'CV_OTHERS_SO' when t1.store_type = '第三方' then 'CV_OTHERS_POP' end store_name,\n",
|
||
"-- 'CV_OTHERS' as corp_cod,\n",
|
||
"-- t2.sales_value - t1.sales_value as sales_value,\n",
|
||
"-- 0,0,\n",
|
||
"-- 'CV' as flag,\n",
|
||
"-- 'CV_OTHERS' as ta\n",
|
||
"-- from(\n",
|
||
"-- -----------------------所有的cv数据\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- platform,\n",
|
||
"-- case when store_type = '平台店' or store_type = '品牌店' then '自营旗舰' else store_type end store_type,\n",
|
||
"-- sum(sales_value) sales_value\n",
|
||
"-- from cv_corp_data\n",
|
||
"-- group by 1,2,3\n",
|
||
"-- )t1\n",
|
||
"-- left join(\n",
|
||
"-- -----------------------cv大数\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- platform,\n",
|
||
"-- case when store_type = '三方' then '第三方' else store_type end store_type,\n",
|
||
"-- sum(sales_value) sales_value\n",
|
||
"-- from dws.dws_zk_ec_by_ta_top_corp\n",
|
||
"-- where ta = 'CV' and lower(rank) = 'total'\n",
|
||
"-- group by 1,2,3\n",
|
||
"-- )t2\n",
|
||
"-- on t1.yyyymm = t2.yyyymm and t1.platform = t2.platform and t1.store_type = t2.store_type\n",
|
||
"-- ),non_cv_all_data as (\n",
|
||
"-- select\n",
|
||
"-- t1.yyyymm,\n",
|
||
"-- t1.pack_id,\n",
|
||
"-- t1.iqvia_pack_code,\n",
|
||
"-- t1.platform,\n",
|
||
"-- t1.store_type,\n",
|
||
"-- t1.store_name,\n",
|
||
"-- t2.corp_cod,\n",
|
||
"-- t1.sales_value,\n",
|
||
"-- t1.sales_unit,\n",
|
||
"-- t1.counting_unit,\n",
|
||
"-- case when t2.ta in ('DM','RD') then 'CVRM' else '' end flag,\n",
|
||
"-- max(t2.ta) ta\n",
|
||
"-- from dws.dws_zk_ec_sales t1\n",
|
||
"-- left join (select distinct iqvia_pack_code,ta,corp_cod,product_id from tmp.tmp_zk_ec_pack_property_corp) t2\n",
|
||
"-- on t1.pack_id = t2.product_id\n",
|
||
"-- where nvl(t2.TA,'') <> 'CV'\n",
|
||
"-- group by 1,2,3,4,5,6,7,8,9,10,11\n",
|
||
"-- )\n",
|
||
"-- select * from all_cv_data\n",
|
||
"-- union\n",
|
||
"-- select * from non_cv_all_data\n",
|
||
"-- -- select * from non_cv_all_data order by sales_value desc"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "417e5776-6bb5-495d-bc80-1b7213db7289",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- --cvrm倒减:关联加工好的配置表,获取ta信息进行倒减\n",
|
||
"-- insert overwrite table tmp.tmp_dm_zk_ec_sales_cv_tmp2\n",
|
||
"-- with all_data as (\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- pack_id,\n",
|
||
"-- iqvia_pack_code,\n",
|
||
"-- platform,\n",
|
||
"-- store_type,\n",
|
||
"-- store_name,\n",
|
||
"-- corp_cod,\n",
|
||
"-- sales_value,\n",
|
||
"-- sales_unit,\n",
|
||
"-- counting_unit,\n",
|
||
"-- flag\n",
|
||
"-- from tmp.tmp_dm_zk_ec_sales_cv_tmp\n",
|
||
"-- union all\n",
|
||
"-- select\n",
|
||
"-- t1.yyyymm,\n",
|
||
"-- 'CVRM_AZ_OTHERS' as pack_id,\n",
|
||
"-- 'CVRM_AZ_OTHERS' as iqvia_pack_code,\n",
|
||
"-- t1.platform,\n",
|
||
"-- t1.store_type,\n",
|
||
"-- case when t1.store_type = '自营旗舰' then 'CVRM_AZ_OTHERS_SO' when t1.store_type = '第三方' then 'CVRM_AZ_OTHERS_POP' end store_name,\n",
|
||
"-- t1.corp_cod,\n",
|
||
"-- t2.sales_value - t1.sales_value as sales_value,\n",
|
||
"-- 0,0,\n",
|
||
"-- 'CVRM' as flag\n",
|
||
"-- from(\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- corp_cod,\n",
|
||
"-- platform,\n",
|
||
"-- case when store_type = '平台店' or store_type = '品牌店' then '自营旗舰' else store_type end store_type,\n",
|
||
"-- sum(sales_value) sales_value\n",
|
||
"-- from tmp.tmp_dm_zk_ec_sales_cv_tmp\n",
|
||
"-- where corp_cod = 'A5Z' and flag in ('CV','CVRM')\n",
|
||
"-- group by 1,2,3,4\n",
|
||
"-- )t1\n",
|
||
"-- left join (\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- CORP_COD,\n",
|
||
"-- platform,\n",
|
||
"-- case when store_type = '三方' then '第三方' else store_type end store_type,\n",
|
||
"-- sum(sales_value) sales_value\n",
|
||
"-- from dws.dws_zk_ec_by_ta_top_corp\n",
|
||
"-- where CORP_COD = 'A5Z' and ta = 'CVRM'\n",
|
||
"-- group by 1,2,3,4\n",
|
||
"-- )t2\n",
|
||
"-- on t1.yyyymm = t2.yyyymm and t1.platform = t2.platform and t1.store_type = t2.store_type\n",
|
||
"-- )\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- pack_id,\n",
|
||
"-- iqvia_pack_code,\n",
|
||
"-- platform,\n",
|
||
"-- store_type,\n",
|
||
"-- store_name,\n",
|
||
"-- corp_cod,\n",
|
||
"-- sales_value,\n",
|
||
"-- sales_unit,\n",
|
||
"-- counting_unit,\n",
|
||
"-- flag\n",
|
||
"-- from all_data\n",
|
||
"-- union all\n",
|
||
"-- select\n",
|
||
"-- t1.yyyymm,\n",
|
||
"-- 'CVRM_OTHERS' as pack_id,\n",
|
||
"-- 'CVRM_OTHERS' as iqvia_pack_code,\n",
|
||
"-- t1.platform,\n",
|
||
"-- t1.store_type,\n",
|
||
"-- case when t1.store_type = '自营旗舰' then 'CVRM_OTHERS_SO' when t1.store_type = '第三方' then 'CVRM_OTHERS_POP' end store_name,\n",
|
||
"-- 'CVRM_OTHERS' as corp_cod,\n",
|
||
"-- t2.sales_value - t1.sales_value as sales_value,\n",
|
||
"-- 0,0,\n",
|
||
"-- 'CVRM' flag\n",
|
||
"-- from (\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- platform,\n",
|
||
"-- case when store_type = '平台店' or store_type = '品牌店' then '自营旗舰' else store_type end store_type,\n",
|
||
"-- sum(sales_value) sales_value\n",
|
||
"-- from all_data\n",
|
||
"-- where flag in ('CV','CVRM')\n",
|
||
"-- group by 1,2,3\n",
|
||
"-- )t1\n",
|
||
"-- left join(\n",
|
||
"-- select\n",
|
||
"-- yyyymm,\n",
|
||
"-- platform,\n",
|
||
"-- case when store_type = '三方' then '第三方' else store_type end store_type,\n",
|
||
"-- sum(sales_value) sales_value\n",
|
||
"-- from dws.dws_zk_ec_by_ta_top_corp\n",
|
||
"-- where ta = 'CVRM' and lower(rank) = 'total'\n",
|
||
"-- group by 1,2,3\n",
|
||
"-- )t2\n",
|
||
"-- on t1.yyyymm = t2.yyyymm and t1.platform = t2.platform and t1.store_type = t2.store_type"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "46ab1bf4-aa35-4931-9675-8dfb49298339",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"--ta倒减并写入事实表:根据加工好的倒减底表中ta字段信息获取ta总数,进行倒减\n",
|
||
"-- 注:倒减逻辑已注释,此处改为直接聚合 dws.dws_zk_ec_sales 数据(QTD粒度)\n",
|
||
"insert overwrite table tmp.tmp_dm_zk_ec_sales\n",
|
||
"select\n",
|
||
" ytd,\n",
|
||
" pack_id,\n",
|
||
" iqvia_pack_code,\n",
|
||
" platform,\n",
|
||
" store_type,\n",
|
||
" store_name,\n",
|
||
" corp_cod,\n",
|
||
" sales_value,\n",
|
||
" sales_unit,\n",
|
||
" counting_unit,\n",
|
||
" 'NORMAL' as flag\n",
|
||
"from (\n",
|
||
" select\n",
|
||
" ytd,\n",
|
||
" pack_id,\n",
|
||
" iqvia_pack_code,\n",
|
||
" platform,\n",
|
||
" store_type,\n",
|
||
" store_name,\n",
|
||
" corp_cod,\n",
|
||
" sum(sales_value) as sales_value,\n",
|
||
" sum(sales_unit) as sales_unit,\n",
|
||
" sum(counting_unit) as counting_unit\n",
|
||
" from dws.dws_zk_ec_sales\n",
|
||
" group by ytd, pack_id, iqvia_pack_code, platform, store_type, store_name, corp_cod\n",
|
||
")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "f4b8428b-d5b5-4214-9578-fd01b4c7d5eb",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- 注:ly 同比数据依赖倒减结果,已移除(QTD粒度)\n",
|
||
"insert overwrite table dm.dm_zk_ec_sales\n",
|
||
"select\n",
|
||
" ytd,\n",
|
||
" max(pack_id) as pack_id,\n",
|
||
" iqvia_pack_code,\n",
|
||
" corp_cod,\n",
|
||
" 'ROC' as audit_cod,\n",
|
||
" platform,\n",
|
||
" case when store_type = '第三方' then 'POP' when store_type in ('平台店','品牌店','自营旗舰') then 'SO' end store_type,\n",
|
||
" store_name,\n",
|
||
" max(PACK_FLAG) as PACK_FLAG,\n",
|
||
" max(PROD_FLAG) as PROD_FLAG,\n",
|
||
" max(flag) as flag,\n",
|
||
" 'EC(Quarterly)' DATA_SOURCE,\n",
|
||
" sum(sales_value) as sales_value,\n",
|
||
" sum(sales_unit) as sales_unit,\n",
|
||
" sum(counting_unit) as counting_unit\n",
|
||
"from tmp.tmp_dm_zk_ec_sales\n",
|
||
"group by ytd, iqvia_pack_code, corp_cod, audit_cod, platform, store_type, store_name, DATA_SOURCE"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"inputWidgets": {},
|
||
"nuid": "c9fb5215-b43a-4326-adfe-f8e56e547426",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"insert overwrite table dws.dws_zk_ec_pack_property\n",
|
||
"select\n",
|
||
" *\n",
|
||
" ,from_utc_timestamp(current_timestamp(),'UTC+8' ) etl_insert_dt\n",
|
||
" ,from_utc_timestamp(current_timestamp(),'UTC+8' ) etl_update_dt\n",
|
||
"from tmp.tmp_ec_temp_market\n",
|
||
"union all\n",
|
||
"select\n",
|
||
"'' iqvia_lineno\n",
|
||
",iqvia_pack_code as iqvia_pack_code\n",
|
||
",'' prod_cod\n",
|
||
",'' iqvia_notes\n",
|
||
",'' new_pack_flag\n",
|
||
",'' is_exists_chpa\n",
|
||
",iqvia_pack_code as product_id\n",
|
||
",'' prescription_nature\n",
|
||
",'' medicine_type\n",
|
||
",'' zk_medicine_tier1\n",
|
||
",'' zk_medicine_tier2\n",
|
||
",'' zk_medicine_tier3\n",
|
||
",'' zk_medicine_tier4\n",
|
||
",'' common_name\n",
|
||
",'' dosage_form\n",
|
||
",'' user_type\n",
|
||
",'' category_name\n",
|
||
",'' product_name\n",
|
||
",'' brand_name\n",
|
||
",'' zk_manu_des\n",
|
||
",'' zk_corp_des\n",
|
||
",'' zk_pack_des\n",
|
||
",'' counting_unit_a\n",
|
||
",'' dosage_unit_a\n",
|
||
",'' unit_a\n",
|
||
",'' app1_cod\n",
|
||
",'' app1_des\n",
|
||
",'' app1_des_c\n",
|
||
",'' app2_cod\n",
|
||
",'' app2_des\n",
|
||
",'' app2_des_c\n",
|
||
",'' app3_cod\n",
|
||
",'' app3_des\n",
|
||
",'' app3_des_c\n",
|
||
",'' atc1_cod\n",
|
||
",'' atc1_des\n",
|
||
",'' atc1_des_c\n",
|
||
",'' atc2_cod\n",
|
||
",'' atc2_des\n",
|
||
",'' atc2_des_c\n",
|
||
",'' atc3_cod\n",
|
||
",'' atc3_des\n",
|
||
",'' atc3_des_c\n",
|
||
",'' atc4_cod\n",
|
||
",'' atc4_des\n",
|
||
",'' atc4_des_c\n",
|
||
",'' bio_desc\n",
|
||
",'' cmps_cod\n",
|
||
",'' cmps_des\n",
|
||
",'' cmps_des_c\n",
|
||
",corp_cod as corp_cod\n",
|
||
",'' corp_des\n",
|
||
",'' corp_des_c\n",
|
||
",'' edl_desc\n",
|
||
",'' eth_otc_desc\n",
|
||
",'' gene_orig_desc\n",
|
||
",'' gqce_desc\n",
|
||
",'' manu_cod\n",
|
||
",'' manu_des\n",
|
||
",'' manu_des_c\n",
|
||
",'' mnfl_cod\n",
|
||
",'' mnfl_des\n",
|
||
",'' nrdl_desc\n",
|
||
",'' pack_des\n",
|
||
",'' stgh_des\n",
|
||
",'' pack_lch\n",
|
||
",'' paed_desc\n",
|
||
",'Others' prod_des\n",
|
||
",'Others' prod_des_c\n",
|
||
",'' tcm_desc\n",
|
||
",'' vbp_desc\n",
|
||
",'' unit\n",
|
||
",'' counting_unit\n",
|
||
",'' dosage_unit\n",
|
||
",'' NRDL_ENTRY_DATE\n",
|
||
",'NON MARKET' Market\n",
|
||
",'' bu\n",
|
||
",1 extend_market_ratio\n",
|
||
",case when iqvia_pack_code like '%AZ%' then 'Y' else 'N' end is_az\n",
|
||
",from_utc_timestamp(current_timestamp(),'UTC+8' ) etl_insert_dt\n",
|
||
",from_utc_timestamp(current_timestamp(),'UTC+8' ) etl_update_dt\n",
|
||
"from (select distinct iqvia_pack_code,corp_cod from dm.dm_zk_ec_sales where iqvia_pack_code not in (select distinct iqvia_pack_code from tmp.tmp_ec_temp_market))\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "d6f3e56c-f8a8-42a0-ad80-2220d0631740",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"insert overwrite table tmp.tmp_dm_zk_ec_pack_property\n",
|
||
"select\n",
|
||
"a.iqvia_lineno\n",
|
||
",a.iqvia_pack_code\n",
|
||
",a.prod_cod\n",
|
||
",a.iqvia_notes\n",
|
||
",a.new_pack_flag\n",
|
||
",a.is_exists_chpa\n",
|
||
",a.product_id\n",
|
||
",a.prescription_nature\n",
|
||
",a.medicine_type\n",
|
||
",a.zk_medicine_tier1\n",
|
||
",a.zk_medicine_tier2\n",
|
||
",a.zk_medicine_tier3\n",
|
||
",a.zk_medicine_tier4\n",
|
||
",a.common_name\n",
|
||
",a.dosage_form\n",
|
||
",a.user_type\n",
|
||
",a.category_name\n",
|
||
",a.product_name\n",
|
||
",a.brand_name\n",
|
||
",a.zk_manu_des\n",
|
||
",a.zk_corp_des\n",
|
||
",a.zk_pack_des\n",
|
||
",a.counting_unit_a\n",
|
||
",a.dosage_unit_a\n",
|
||
",a.unit_a\n",
|
||
",a.app1_cod\n",
|
||
",a.app1_des\n",
|
||
",a.app1_des_c\n",
|
||
",a.app2_cod\n",
|
||
",a.app2_des\n",
|
||
",a.app2_des_c\n",
|
||
",a.app3_cod\n",
|
||
",a.app3_des\n",
|
||
",a.app3_des_c\n",
|
||
",a.atc1_cod\n",
|
||
",a.atc1_des\n",
|
||
",a.atc1_des_c\n",
|
||
",a.atc2_cod\n",
|
||
",a.atc2_des\n",
|
||
",a.atc2_des_c\n",
|
||
",a.atc3_cod\n",
|
||
",a.atc3_des\n",
|
||
",a.atc3_des_c\n",
|
||
",a.atc4_cod\n",
|
||
",a.atc4_des\n",
|
||
",a.atc4_des_c\n",
|
||
",a.bio_desc\n",
|
||
",a.cmps_cod\n",
|
||
",a.cmps_des\n",
|
||
",a.cmps_des_c\n",
|
||
",COALESCE(c.corp_cod,b.corp_cod,a.corp_cod) corp_cod\n",
|
||
",COALESCE(c.corp_des,b.corp_des,a.corp_des) corp_des\n",
|
||
",COALESCE(d.corp_des_c,a.corp_des_c ) corp_des_c\n",
|
||
",a.edl_desc\n",
|
||
",a.eth_otc_desc\n",
|
||
",a.gene_orig_desc\n",
|
||
",a.gqce_desc\n",
|
||
",COALESCE(c.manu_cod,b.manu_cod,a.manu_cod) manu_cod\n",
|
||
",COALESCE(c.manu_des,b.manu_des,a.manu_des) manu_des\n",
|
||
",COALESCE(e.manu_des_c,a.manu_des_c) manu_des_c\n",
|
||
",a.mnfl_cod\n",
|
||
",a.mnfl_des\n",
|
||
",a.nrdl_desc\n",
|
||
",a.pack_des\n",
|
||
",a.stgh_des\n",
|
||
",a.pack_lch\n",
|
||
",a.paed_desc\n",
|
||
",a.prod_des\n",
|
||
",a.prod_des_c\n",
|
||
",a.tcm_desc\n",
|
||
",a.vbp_desc\n",
|
||
",a.unit\n",
|
||
",a.counting_unit\n",
|
||
",a.dosage_unit\n",
|
||
",a.NRDL_ENTRY_DATE\n",
|
||
",a.Market\n",
|
||
",a.bu\n",
|
||
",a.extend_market_ratio\n",
|
||
",a.is_az\n",
|
||
"from dws.dws_zk_ec_pack_property a\n",
|
||
"left join (select right(concat('000000000',prod_cod ),9) prod_cod,corp_cod,corp_des,manu_cod,manu_des from dwd.dwd_gnd_tbl_corp_change where pack_cod is null ) b\n",
|
||
"on right(concat('000000000',A.prod_cod ),9)= b.prod_cod\n",
|
||
"left join (select if( pack_cod REGEXP '^[0-9]',right(concat('000000000000',pack_cod),12),pack_cod) pack_cod,corp_cod,corp_des,manu_cod,manu_des from dwd.dwd_gnd_tbl_corp_change where pack_cod is not null ) c\n",
|
||
"on a.iqvia_pack_code = c.pack_cod\n",
|
||
"left join (select distinct corp_cod,corp_des_c from dwd.dwd_gnd_ext_retail_pack_property) d\n",
|
||
"on coalesce(C.corp_cod,B.corp_cod ) = d.corp_cod\n",
|
||
"Left join (select distinct manu_cod,manu_des,manu_des_c from dwd.dwd_gnd_ext_retail_pack_property) e\n",
|
||
"On coalesce(C.manu_cod,B.manu_cod ) = e.manu_cod"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "46897086-86d3-475c-aa97-eb99b844f340",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"------将事实表倒减之后的维度信息补充到维度表里\n",
|
||
"insert overwrite table dm.dm_zk_ec_pack_property\n",
|
||
"select\n",
|
||
" CASE when a.iqvia_pack_code IN ('CVRM_AZ_OTHERS','CVRM_OTHERS') THEN 'CVRM_OTHER Market'\n",
|
||
" WHEN a.iqvia_pack_code IN ('CV_AZ_OTHERS','CV_OTHERS') THEN 'CV_OTHER Market'\n",
|
||
" WHEN A.iqvia_pack_code IN ('OTHERS_AZ_TA','OTHERS_TA') THEN 'OTHERS Market'\n",
|
||
" ELSE a.market\n",
|
||
" END ||'_'||a.iqvia_pack_code MARKET_PACK_KEY\n",
|
||
",a.iqvia_lineno\n",
|
||
",a.iqvia_pack_code\n",
|
||
",a.prod_cod\n",
|
||
",a.iqvia_notes\n",
|
||
",a.new_pack_flag\n",
|
||
",a.is_exists_chpa\n",
|
||
",'' Family_Code\n",
|
||
",'' Family_Name\n",
|
||
",'' BrandType\n",
|
||
",'' AZ_MAIN\n",
|
||
",'' AZ_Related\n",
|
||
",t5.KEY_COMPETITOR\n",
|
||
",a.product_id\n",
|
||
",a.prescription_nature\n",
|
||
",a.medicine_type\n",
|
||
",a.zk_medicine_tier1\n",
|
||
",a.zk_medicine_tier2\n",
|
||
",a.zk_medicine_tier3\n",
|
||
",a.zk_medicine_tier4\n",
|
||
",a.common_name\n",
|
||
",a.dosage_form\n",
|
||
",a.user_type\n",
|
||
",a.category_name\n",
|
||
",a.product_name\n",
|
||
",a.brand_name\n",
|
||
",a.zk_manu_des\n",
|
||
",a.zk_corp_des\n",
|
||
",a.zk_pack_des\n",
|
||
",a.counting_unit_a\n",
|
||
",a.dosage_unit_a\n",
|
||
",a.unit_a\n",
|
||
",a.app1_cod\n",
|
||
",a.app1_des\n",
|
||
",a.app1_des_c\n",
|
||
",a.app2_cod\n",
|
||
",a.app2_des\n",
|
||
",a.app2_des_c\n",
|
||
",a.app3_cod\n",
|
||
",a.app3_des\n",
|
||
",a.app3_des_c\n",
|
||
",a.atc1_cod\n",
|
||
",a.atc1_des\n",
|
||
",a.atc1_des_c\n",
|
||
",a.atc2_cod\n",
|
||
",a.atc2_des\n",
|
||
",a.atc2_des_c\n",
|
||
",a.atc3_cod\n",
|
||
",a.atc3_des\n",
|
||
",a.atc3_des_c\n",
|
||
",a.atc4_cod\n",
|
||
",a.atc4_des\n",
|
||
",a.atc4_des_c\n",
|
||
",a.bio_desc\n",
|
||
",a.cmps_cod\n",
|
||
",a.cmps_des\n",
|
||
",a.cmps_des_c\n",
|
||
",CASE WHEN a.iqvia_pack_code LIKE '%AZ%' THEN 'A5Z' else a.CORP_COD END\n",
|
||
"\t\t\t\t\t\t\t\tcorp_cod\n",
|
||
",CASE\n",
|
||
"\tWHEN a.iqvia_pack_code LIKE '%AZ%' THEN 'ASTRAZENECA'\n",
|
||
"\tWHEN a.corp_des like '%GROUP%' THEN replace(a.corp_des,' GROUP','')\n",
|
||
"\telse a.CORP_DES END corp_des\n",
|
||
",CASE WHEN a.iqvia_pack_code LIKE '%AZ%' THEN '阿斯利康制药集团' else a.CORP_DES_C END\n",
|
||
" CORP_DES_C\n",
|
||
",a.edl_desc\n",
|
||
",a.eth_otc_desc\n",
|
||
",a.gene_orig_desc\n",
|
||
",a.gqce_desc\n",
|
||
",a.manu_cod\n",
|
||
",a.manu_des\n",
|
||
",a.manu_des_c\n",
|
||
",a.mnfl_cod\n",
|
||
",a.mnfl_des\n",
|
||
",a.nrdl_desc\n",
|
||
",a.pack_des\n",
|
||
",a.stgh_des\n",
|
||
",a.pack_lch\n",
|
||
",a.paed_desc\n",
|
||
",a.prod_des\n",
|
||
",a.prod_des_c\n",
|
||
",a.tcm_desc\n",
|
||
",a.vbp_desc\n",
|
||
",a.unit\n",
|
||
",a.counting_unit\n",
|
||
",a.dosage_unit\n",
|
||
",a.NRDL_ENTRY_DATE\n",
|
||
",CASE WHEN a.iqvia_pack_code IN ('CVRM_AZ_OTHERS','CVRM_OTHERS') THEN 'CVRM_OTHER Market'\n",
|
||
" WHEN a.iqvia_pack_code IN ('CV_AZ_OTHERS','CV_OTHERS') THEN 'CV_OTHER Market'\n",
|
||
" WHEN A.iqvia_pack_code IN ('OTHERS_AZ_TA','OTHERS_TA') THEN 'OTHERS Market'\n",
|
||
" ELSE a.market\n",
|
||
" END market\n",
|
||
",a.bu\n",
|
||
",a.extend_market_ratio\n",
|
||
",a.is_az\n",
|
||
",nvl(b.class, 'Others') class\n",
|
||
",CASE WHEN a.iqvia_pack_code IN ('CVRM_AZ_OTHERS','CVRM_OTHERS') THEN 'CVRM'\n",
|
||
" WHEN a.iqvia_pack_code IN ('CV_AZ_OTHERS','CV_OTHERS') THEN 'CV'\n",
|
||
" ELSE c.ta\n",
|
||
" END TA\n",
|
||
"from tmp.tmp_dm_zk_ec_pack_property a\n",
|
||
"left join dwd.dwd_gnd_ext_retail_dim_ta c\n",
|
||
"on c.market = a.Market\n",
|
||
"left join dwd.dwd_gnd_tblclass b\n",
|
||
"on a.Market = case when b.market is null then a.Market else b.market end\n",
|
||
"and nvl(a.iqvia_pack_code,'') = case when b.pack_code is null then nvl(a.iqvia_pack_code,'') else b.pack_code end\n",
|
||
"and nvl(a.prod_cod,'') = case when b.product_code is null then nvl(a.prod_cod,'') else b.product_code end\n",
|
||
"and nvl(a.cmps_cod,'') = case when b.molecule_code is null then nvl(a.cmps_cod,'') else right(concat('000000',b.molecule_code),6) end\n",
|
||
"and nvl(a.corp_cod,'') = case when b.corporation_code is null then nvl(a.corp_cod,'') else b.corporation_code end\n",
|
||
"and nvl(a.manu_cod,'') = case when b.manufacturer_code is null then nvl(a.manu_cod,'') else b.manufacturer_code end\n",
|
||
"and nvl(a.app1_cod,'') = case when b.nfc1_code is null then nvl(a.app1_cod,'') else b.nfc1_code end\n",
|
||
"and nvl(a.app2_cod,'') = case when b.nfc2_code is null then nvl(a.app2_cod,'') else b.nfc2_code end\n",
|
||
"and nvl(a.app3_cod,'') = case when b.nfc3_code is null then nvl(a.app3_cod,'') else b.nfc3_code end\n",
|
||
"and nvl(a.atc1_cod,'') = case when b.atc1_code is null then nvl(a.atc1_cod,'') else b.atc1_code end\n",
|
||
"and nvl(a.atc2_cod,'') = case when b.atc2_code is null then nvl(a.atc2_cod,'') else b.atc2_code end\n",
|
||
"and nvl(a.atc3_cod,'') = case when b.atc3_code is null then nvl(a.atc3_cod,'') else b.atc3_code end\n",
|
||
"and nvl(a.atc4_cod,'') = case when b.atc4_code is null then nvl(a.atc4_cod,'') else b.atc4_code end\n",
|
||
"and nvl(a.stgh_des,'') = case when b.strength is null then nvl(a.stgh_des,'') else b.strength end\n",
|
||
"left join (select distinct MARKET,PACK_CODE as PACK_COD,KEY_COMPETITOR from DM.DM_TD_EXT_CHPA_MARKET_PACK_MAPPING) t5\n",
|
||
"on a.market = t5.MARKET\n",
|
||
"and a.iqvia_pack_code = t5.PACK_COD\n",
|
||
"\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "f13443fe-0759-4691-ab7a-c21d5c11773d",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"insert overwrite table dm.dm_zk_ec_market_property\n",
|
||
"select distinct\n",
|
||
"iqvia_pack_code,market,ta\n",
|
||
"from dm.dm_zk_ec_pack_property"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "265ea9d8-69de-49a4-976e-2038ca0f26fe",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"insert overwrite table dm.dm_zk_ec_market_ratio\n",
|
||
"select distinct\n",
|
||
" concat(a.Market,'_',a.iqvia_pack_code) as market_pack_key,\n",
|
||
" a.iqvia_pack_code as pack_cod,\n",
|
||
" a.prod_des,\n",
|
||
" a.cmps_des,\n",
|
||
" a.corp_cod,\n",
|
||
" a.Market,\n",
|
||
" a.extend_market_ratio as value_market_ratio,\n",
|
||
" a.extend_market_ratio as unit_market_ratio,\n",
|
||
" coalesce(\n",
|
||
" case when c.ratio is null then a.extend_market_ratio*d.ratio\n",
|
||
" else a.extend_market_ratio*c.ratio end,1) as countingunit_market_ratio\n",
|
||
"from tmp.tmp_ec_temp_market a\n",
|
||
"left join (--pack\n",
|
||
" select\n",
|
||
"\t\tmarket,\n",
|
||
"\t\tcmps_cod,\n",
|
||
"\t\tcmps_des,\n",
|
||
"\t\tif( pack_cod REGEXP '^[0-9]',right(concat('000000000000',pack_cod),12),pack_cod) pack_cod,--right(concat('0000000',pack_cod ),7)\n",
|
||
"\t\tpack_des,\n",
|
||
"\t\tlevel,\n",
|
||
"\t\ttype,\n",
|
||
"\t\tcast(ratio as float) as ratio,\n",
|
||
"\t\tcast(starttime as int) starttime,\n",
|
||
"\t\tcast (endtime as int) endtime\n",
|
||
" from dwd.dwd_gnd_ims_tblbrandratio\n",
|
||
" where UPPER(TYPE) = 'COUNTINGUNIT' and UPPER(Level) = 'PACK'\n",
|
||
")c on a.Market = c.market and a.iqvia_pack_code = if( c.pack_cod REGEXP '^[0-9]',right(concat('000000000000',c.pack_cod),12),c.pack_cod)--right(concat('0000000',c.pack_cod),7)\n",
|
||
"left join(--molecule\n",
|
||
" select\n",
|
||
"\t\tmarket,\n",
|
||
"\t\tcmps_cod,\n",
|
||
"\t\tcmps_des,\n",
|
||
"\t\tif( pack_cod REGEXP '^[0-9]',right(concat('000000000000',pack_cod),12),pack_cod) pack_cod,--right(concat('0000000',pack_cod ),7)\n",
|
||
"\t\tpack_des,\n",
|
||
"\t\tlevel,\n",
|
||
"\t\ttype,\n",
|
||
"\t\tcast(ratio as float) as ratio,\n",
|
||
"\t\tcast(starttime as int) starttime,\n",
|
||
"\t\tcast (endtime as int) endtime\n",
|
||
" from dwd.dwd_gnd_ims_tblbrandratio\n",
|
||
" where UPPER(TYPE) = 'COUNTINGUNIT' and UPPER(Level) = 'MOLECULE'\n",
|
||
")d on a.Market = d.market and a.cmps_cod = right(concat('000000',d.cmps_cod ),6)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "46161520-e1e0-40f7-b956-e727faf700d4",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"create or replace table dm.dm_zk_ec_geo\n",
|
||
"using delta as\n",
|
||
"select\n",
|
||
" 'ROC' as audit_cod,\n",
|
||
" '全国' as city_c,\n",
|
||
" 'national' as city_e,\n",
|
||
" '全国' as province_c,\n",
|
||
" 'national' as province_e;"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "58cce78c-5bc2-4471-acda-ad78a8e94b27",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"---------------------------------------将直取部分数据处理成KPI形式(QTD粒度)-----------------------------------------\n",
|
||
"insert overwrite table tmp.tmp_zk_ec_sales_kpi_tmp\n",
|
||
"select\n",
|
||
" b.CORP_COD,\n",
|
||
" '' as ytd,\n",
|
||
" a.ytd as ytd_src,\n",
|
||
" a.platform,\n",
|
||
" case when a.store_type = '三方' then '第三方' else a.store_type end store_type ,\n",
|
||
" 'ROC' as geo_key,\n",
|
||
"'top_yoygr' as KPI_name,\n",
|
||
"a.yoy_gr as Kpi_val,\n",
|
||
"c.yoy_gr as Kpi_val_ly,\n",
|
||
"'' as str_kpi_val,\n",
|
||
"'' as str_kpi_val_ly,\n",
|
||
"'' as str_kpi_vol,\n",
|
||
"'' as str_kpi_vol_ly,\n",
|
||
"case when upper(a.rank) = 'TTL MKT' then 'Y' else 'N' end total_flag,\n",
|
||
"'' as ta\n",
|
||
"from dwd.dwd_gnd_ec_b2c_top10_drives_brand a\n",
|
||
"left join (select distinct ZK_Corp_C,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total where (ZK_Corp_C = '东阳光' and ZK_Prod_C is null) or ZK_Corp_C != '东阳光') b\n",
|
||
"on a.corp = b.ZK_Corp_C\n",
|
||
"left join dwd.dwd_gnd_ec_b2c_top10_drives_brand c\n",
|
||
"on a.corp = c.corp\n",
|
||
"and a.ytd = c.ytd + 4\n",
|
||
"and a.platform = c.platform\n",
|
||
"and a.store_type = c.store_type\n",
|
||
"union all\n",
|
||
"select\n",
|
||
" b.CORP_COD,\n",
|
||
" '' as ytd,\n",
|
||
" a.ytd as ytd_src,\n",
|
||
" a.platform,\n",
|
||
" case when a.store_type = '三方' then '第三方' else a.store_type end store_type ,\n",
|
||
" 'ROC' as geo_key,\n",
|
||
"'top1_brand_gr' as KPI_name,\n",
|
||
"a.top1_brand_gr as Kpi_val,\n",
|
||
"c.top1_brand_gr as Kpi_val_ly,\n",
|
||
"'' as str_kpi_val,\n",
|
||
"'' as str_kpi_val_ly,\n",
|
||
"'' as str_kpi_vol,\n",
|
||
"'' as str_kpi_vol_ly,\n",
|
||
"case when upper(a.rank) = 'TTL MKT' then 'Y' else 'N' end total_flag,\n",
|
||
"'' as ta\n",
|
||
"from dwd.dwd_gnd_ec_b2c_top10_drives_brand a\n",
|
||
"left join (select distinct ZK_Corp_C,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total where (ZK_Corp_C = '东阳光' and ZK_Prod_C is null) or ZK_Corp_C != '东阳光') b\n",
|
||
"on a.corp = b.ZK_Corp_C\n",
|
||
"left join dwd.dwd_gnd_ec_b2c_top10_drives_brand c\n",
|
||
"on a.corp = c.corp\n",
|
||
"and a.ytd = c.ytd + 4\n",
|
||
"and a.platform = c.platform\n",
|
||
"and a.store_type = c.store_type\n",
|
||
"union all\n",
|
||
"select\n",
|
||
" b.CORP_COD,\n",
|
||
" '' as ytd,\n",
|
||
" a.ytd as ytd_src,\n",
|
||
" a.platform,\n",
|
||
" case when a.store_type = '三方' then '第三方' else a.store_type end store_type,\n",
|
||
" 'ROC' as geo_key,\n",
|
||
"'top1_brand_val' as KPI_name,\n",
|
||
"'' as Kpi_val,\n",
|
||
"'' as Kpi_val_ly,\n",
|
||
"a.top1_brand_val as str_kpi_val,\n",
|
||
"'' as str_kpi_val_ly,\n",
|
||
"'' as str_kpi_vol,\n",
|
||
"'' as str_kpi_vol_ly,\n",
|
||
"case when upper(a.rank) = 'TTL MKT' then 'Y' else 'N' end total_flag,\n",
|
||
"'' as ta\n",
|
||
"from dwd.dwd_gnd_ec_b2c_top10_drives_brand a\n",
|
||
"left join (select distinct ZK_Corp_C,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total where (ZK_Corp_C = '东阳光' and ZK_Prod_C is null) or ZK_Corp_C != '东阳光') b\n",
|
||
"on a.corp = b.ZK_Corp_C\n",
|
||
"union all\n",
|
||
"select\n",
|
||
" b.CORP_COD,\n",
|
||
" '' as ytd,\n",
|
||
" a.ytd as ytd_src,\n",
|
||
" a.platform,\n",
|
||
" case when a.store_type = '三方' then '第三方' else a.store_type end store_type,\n",
|
||
" 'ROC' as geo_key,\n",
|
||
" 'incremental_brand' as KPI_name,\n",
|
||
" '' as Kpi_val,\n",
|
||
" '' as Kpi_val_ly,\n",
|
||
" a.growth_driver_brand_val as str_kpi_val,\n",
|
||
" '' as str_kpi_val_ly,\n",
|
||
" '' as str_kpi_vol,\n",
|
||
" '' as str_kpi_vol_ly,\n",
|
||
" case when upper(a.rank) = 'TTL MKT' then 'Y' else 'N' end total_flag,\n",
|
||
" '' as ta\n",
|
||
"from dwd.dwd_gnd_ec_b2c_top10_drives_brand a\n",
|
||
"left join (select distinct ZK_Corp_C,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total where (ZK_Corp_C = '东阳光' and ZK_Prod_C is null) or ZK_Corp_C != '东阳光') b\n",
|
||
"on a.corp = b.ZK_Corp_C\n",
|
||
"union all\n",
|
||
"select\n",
|
||
" b.CORP_COD,\n",
|
||
" '' as ytd,\n",
|
||
" a.ytd as ytd_src,\n",
|
||
" a.platform,\n",
|
||
" case when a.store_type = '三方' then '第三方' else a.store_type end store_type,\n",
|
||
" 'ROC' as geo_key,\n",
|
||
" 'incremental_brand_gr' as KPI_name,\n",
|
||
" a.growth_driver_brand_gr as Kpi_val,\n",
|
||
" c.growth_driver_brand_gr as Kpi_val_ly,\n",
|
||
" '' as str_kpi_val,\n",
|
||
" '' as str_kpi_val_ly,\n",
|
||
" '' as str_kpi_vol,\n",
|
||
" '' as str_kpi_vol_ly,\n",
|
||
" case when upper(a.rank) = 'TTL MKT' then 'Y' else 'N' end total_flag,\n",
|
||
" '' as ta\n",
|
||
"from dwd.dwd_gnd_ec_b2c_top10_drives_brand a\n",
|
||
"left join (select distinct ZK_Corp_C,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total where (ZK_Corp_C = '东阳光' and ZK_Prod_C is null) or ZK_Corp_C != '东阳光') b\n",
|
||
"on a.corp = b.ZK_Corp_C\n",
|
||
"left join dwd.dwd_gnd_ec_b2c_top10_drives_brand c\n",
|
||
"on a.corp = c.corp\n",
|
||
"and a.ytd = c.ytd + 4\n",
|
||
"and a.platform = c.platform\n",
|
||
"and a.store_type = c.store_type\n",
|
||
"union all\n",
|
||
"select\n",
|
||
" b.CORP_COD,\n",
|
||
" a.ytd as ytd,\n",
|
||
" '' as ytd_src,\n",
|
||
" a.platform,\n",
|
||
" a.store_type,\n",
|
||
" 'ROC' as geo_key,\n",
|
||
" 'top_corp_sales' as KPI_name,\n",
|
||
" replace(a.sales_value,',','' ) as Kpi_val,\n",
|
||
" replace(c.sales_value,',','' ) as Kpi_val_ly,\n",
|
||
" '' as str_kpi_val,\n",
|
||
" '' as str_kpi_val_ly,\n",
|
||
" '' as str_kpi_vol,\n",
|
||
" '' as str_kpi_vol_ly,\n",
|
||
" case when lower(a.rank) = 'total' then 'Y' else 'N' end total_flag,\n",
|
||
" a.ta\n",
|
||
"from dwd.dwd_gnd_ec_ta_overview a\n",
|
||
"left join (select distinct ZK_Corp_C,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total where (ZK_Corp_C = '东阳光' and ZK_Prod_C is null) or ZK_Corp_C != '东阳光') b\n",
|
||
"on a.corp_des = b.ZK_Corp_C\n",
|
||
"left join dwd.dwd_gnd_ec_ta_overview c\n",
|
||
"on a.ytd = c.ytd + 4\n",
|
||
"and a.corp_des = c.corp_des\n",
|
||
"and a.platform = c.platform\n",
|
||
"and a.store_type = c.store_type\n",
|
||
"and a.ta = c.ta\n",
|
||
"union all\n",
|
||
"select distinct\n",
|
||
" b.CORP_COD,\n",
|
||
" '' as ytd,\n",
|
||
" a.ytd as ytd_src,\n",
|
||
" a.platform,\n",
|
||
" a.store_type,\n",
|
||
" 'ROC' as geo_key,\n",
|
||
" 'top_rank' as KPI_name,\n",
|
||
" a.rank as Kpi_val,\n",
|
||
" '' as Kpi_val_ly,\n",
|
||
" '' as str_kpi_val,\n",
|
||
" '' as str_kpi_val_ly,\n",
|
||
" '' as str_kpi_vol,\n",
|
||
" '' as str_kpi_vol_ly,\n",
|
||
" case when lower(a.rank) = 'total' then 'Y' else 'N' end total_flag,\n",
|
||
" a.ta\n",
|
||
"from dwd.dwd_gnd_ec_ta_overview a\n",
|
||
"left join (select distinct ZK_Corp_C,CORP_COD from dwd.dwd_inc_gnd_retail_b2c_label_total where (ZK_Corp_C = '东阳光' and ZK_Prod_C is null) or ZK_Corp_C != '东阳光') b\n",
|
||
"on a.corp_des = b.ZK_Corp_C"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "77737fe1-cfb1-46d0-9624-7231e7c84821",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- KPI最终输出(QTD粒度)\n",
|
||
"insert overwrite table dm.dm_zk_ec_sales_kpi\n",
|
||
"select\n",
|
||
" case when total_flag = 'Y' then 'TTL MKT' else nvl(CORP_COD,'') end CORP_COD ,\n",
|
||
" case\n",
|
||
" when ytd <> '' then concat(year(ytd), 'Q', quarter(ytd))\n",
|
||
" when ytd_src <> '' then concat(year(ytd_src), 'Q', quarter(ytd_src))\n",
|
||
" else ''\n",
|
||
" end as ytd,\n",
|
||
" case when ytd <> '' or ytd_src <> '' then 'Q' else 'N' end as freq,\n",
|
||
" nvl(platform,'') as platform,\n",
|
||
" case when store_type = '自营旗舰' then 'SO'\n",
|
||
" when store_type = '第三方' then 'POP' else nvl(store_type,'') end store_type,\n",
|
||
" nvl(geo_key,'') as geo_key,\n",
|
||
" nvl(KPI_name,'') as KPI_name,\n",
|
||
" nvl(cast(Kpi_val as double),'') Kpi_val,\n",
|
||
" nvl(cast(Kpi_val_ly as double),'') Kpi_val_ly,\n",
|
||
" nvl(str_kpi_val,'') as str_kpi_val,\n",
|
||
" nvl(str_kpi_val_ly,'') as str_kpi_val_ly,\n",
|
||
" nvl(str_kpi_vol,'') as str_kpi_vol,\n",
|
||
" nvl(str_kpi_vol_ly,'') as str_kpi_vol_ly,\n",
|
||
" nvl(total_flag,'') as total_flag,\n",
|
||
" case when ta = 'NIAD' then 'DM' when ta = 'RX Total' then '' else nvl(ta,'') end ta\n",
|
||
"from tmp.tmp_zk_ec_sales_kpi_tmp"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {},
|
||
"inputWidgets": {},
|
||
"nuid": "32e83ce3-a648-4ccc-b376-3c4d88271ed7",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"source": [
|
||
"## NIAD Date"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"collapsed": true,
|
||
"inputWidgets": {},
|
||
"nuid": "8b126179-4e73-4802-94f4-1f8b42cc60d7",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"-- 计算NIAD的时间是否比其他数据源先来数据 chenwu\n",
|
||
"CREATE OR REPLACE TABLE tmp.tmp_dm_td_ext_ec_niad_month as\n",
|
||
"WITH all_ec_data (\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_hm_jd_2025before\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_hm_jd_2025after\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_hm_tm_2206after\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_hm_tm_2206before\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_gastritis_23after\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_gastritis_23before\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_re\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_dm_statins_xzk\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_dm_23before\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_dm_23after\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NOTNIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_hm_tm_2403after\n",
|
||
" UNION ALL\n",
|
||
" SELECT\n",
|
||
" MAX(TIME) month,\n",
|
||
" 'NIAD' AS DATATYPE\n",
|
||
" FROM\n",
|
||
" dwd.dwd_gnd_ec_zkb2c_dm_26after\n",
|
||
")\n",
|
||
"SELECT\n",
|
||
" MAX(t1.month) as NIAD_MONTH,\n",
|
||
" max(t2.month) OTHERS_MONTH\n",
|
||
"FROM\n",
|
||
" all_ec_data t1\n",
|
||
" LEFT JOIN (\n",
|
||
" SELECT\n",
|
||
" MAX(month) as month\n",
|
||
" FROM\n",
|
||
" all_ec_data\n",
|
||
" WHERE\n",
|
||
" datatype = 'NOTNIAD'\n",
|
||
" ) t2\n",
|
||
"WHERE\n",
|
||
" t1.datatype = 'NIAD'"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 0,
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+cell": {
|
||
"cellMetadata": {
|
||
"byteLimit": 2048000,
|
||
"rowLimit": 10000
|
||
},
|
||
"inputWidgets": {},
|
||
"nuid": "a62efe20-3f58-4091-97c8-6762b7f96fe8",
|
||
"showTitle": false,
|
||
"tableResultSettingsMap": {},
|
||
"title": ""
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"select * from tmp.tmp_dm_td_ext_ec_niad_month"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"application/vnd.databricks.v1+notebook": {
|
||
"computePreferences": null,
|
||
"dashboards": [],
|
||
"environmentMetadata": null,
|
||
"inputWidgetPreferences": null,
|
||
"language": "sql",
|
||
"notebookMetadata": {
|
||
"pythonIndentUnit": 4
|
||
},
|
||
"notebookName": "03 ec_load_data",
|
||
"widgets": {}
|
||
},
|
||
"language_info": {
|
||
"name": "sql"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 0
|
||
}
|