Files
MarketAnalysis-ETL/county/02 tmp_imscounty_Result.sql
chenwu 832c7bcd69 new file: 01 dm_tf_external_sales.sql
new file:   02 dm_td_external_keycompatitor.sql
	new file:   03 dm_td_external_brand_market.sql
	new file:   04 dm_td_external_calendar.sql
	new file:   05 dm_td_external_exchangerate.sql
	new file:   07 dm_td_external_packinfo.sql
	new file:   08 dm_td_external_corp.sql
	new file:   09 dm_td_external_geo_type.sql
	new file:   11 DM_TD_EXTERNAL_MARKET_NEW.sql
	new file:   12 dm_td_external_org.sql
	new file:   13 external auth.sql
	new file:   14 dm_tf_external_retail_special_bkp.sql
	new file:   AIA/01 dm_aia_pack_property.sql
	new file:   AIA/02 dm_ext_aia_sales.sql
	new file:   AIA/02 dm_ext_aia_sales_bakup_20230327.sql
	new file:   AIA/03 dm_aia_flag.sql
	new file:   AIA/04 dm_aia_provided_flag.sql
	new file:   AIA/06 DM_TD_EXT_AIA_PACK_PROPERTY.sql
	new file:   AIA/07 DM_TD_EXT_AIA_PACK2MARKET.sql
	new file:   AIA/08 DM_TD_EXT_AIA_MARKET_RATIO.sql
	new file:   AIA/09 DM_TD_EXT_AIA_MARKET_BRAND_RATIO.sql
	new file:   AIA/10 DM_TD_EXT_AIA_MARKET_PACK_MAPPING.sql
	new file:   AIA/11 DM_TD_EXT_AIA_TARGET_INST.sql
	new file:   AIA/11 dm_aia_targethp_flag.sql
	new file:   "AIA/z_03 dm_aia_flag_\345\244\207\344\273\275\347\224\250.sql"
	new file:   CHC/01 dm_chc_pack_property.sql
	new file:   CHC/02 DM_TF_EXT_CHC_SALES.sql
	new file:   CHC/03 DM_TD_EXT_CHC_PACK_PROPERTY.sql
	new file:   CHC/04 DM_TD_EXT_CHC_PACK2MARKET.sql
	new file:   CHC/05 DM_TD_EXT_CHC_MARKET_RATIO.sql
	new file:   CHC/06 DM_TD_EXT_CHC_MARKET_BRAND_RATIO.sql
	new file:   CHC/07 DM_TD_EXT_CHC_MARKET_PACK_MAPPING.sql
	new file:   CHPA/01 dwd_ims_atc_hierarchy.sql
	new file:   CHPA/01 dwd_ims_nfc_hierarchy.sql
	new file:   CHPA/01 dwd_ims_td_manufacturer_corp.sql
	new file:   CHPA/01 dwd_ims_td_pack_property.sql
	new file:   CHPA/01 dwd_update.sql
	new file:   CHPA/01_FB_BLOB_TO_DWD.sql
	new file:   CHPA/02 DWS_IMS_TD_GEO.sql
	new file:   CHPA/02 dws_ims_td_atc_cn.sql
	new file:   CHPA/02 dws_ims_td_corp_cn.sql
	new file:   CHPA/02 dws_ims_td_date.sql
	new file:   CHPA/02 dws_ims_td_manu_cn.sql
	new file:   CHPA/02 dws_ims_td_market.sql
	new file:   CHPA/02 dws_ims_td_market_ta.sql
	new file:   CHPA/02 dws_ims_td_nfc_cn.sql
	new file:   CHPA/02 dws_ims_td_prod_cn.sql
	new file:   CHPA/02 tmp_ims_td_prod_tmp.sql
	new file:   CHPA/02 tmp_ims_tf_fact_sales.sql
	new file:   CHPA/03 DM_TD_EXT_CHPA_MARKET_BRAND_RATIO.sql
	new file:   CHPA/03 DM_TD_EXT_CHPA_MARKET_PACK_MAPPING.sql
	new file:   CHPA/03 DM_TD_EXT_CHPA_MARKET_RATIO.sql
	new file:   CHPA/03 DM_TD_EXT_CHPA_PACK2MARKET.sql
	new file:   CHPA/03 DM_TD_EXT_CHPA_PACK_PROPERTY.sql
	new file:   CHPA/03 DM_TF_EXT_CHPA_SALES.sql
	new file:   CHPA/03 dm_ims_td_calendar.sql
	new file:   CHPA/03 dm_ims_td_geo.sql
	new file:   CHPA/03 dm_ims_td_market_property.sql
	new file:   CHPA/03 dm_ims_td_org.sql
	new file:   CHPA/03 dm_ims_td_org_hvh.sql
	new file:   CHPA/03 dm_ims_td_pack_property.sql
	new file:   CHPA/03 dm_ims_tf_sales.sql
	new file:   CHPA/03 dm_td_chpa_market_definition.sql
	new file:   CHPA/03 dm_td_ims_city_mapping.sql
	new file:   EC/03 ec_load_data.sql
	new file:   EC/04 DM_TD_EXT_EC_PACK_PROPERTY.sql
	new file:   EC/05 DM_TF_EXT_EC_SALES.sql
	new file:   EC/06 DM_TD_EXT_EC_PACK2MARKET.sql
	new file:   EC/07 DM_TD_EXT_EC_MARKET_RATIO.sql
	new file:   EC/08 DM_TD_EXT_EC_MARKET_BRAND_RATIO.sql
	new file:   EC/09 DM_TD_EXT_EC_MARKET_PACK_MAPPING.sql
	new file:   EC/1 (ec)blob_to_dwd.sql
	new file:   EC/2 dwd_inc_gnd_ext_ec_nationnal_pack_union_all.py
	new file:   Merged_Data/Merged_Data_Config_table_bkp.sql
	new file:   Merged_Data/Merged_Data_Config_table_bymonth.sql
	new file:   Merged_Data/dm_tf_exteranl_sales_merged_data_dtp_others_bkp.sql
	new file:   Merged_Data/dm_tf_exteranl_sales_merged_data_dtp_others_bymonth_bkp.sql
	new file:   ORG/DM_TD_EXT_AIA_ORG.sql
	new file:   ORG/DM_TD_EXT_CHC_ORG.sql
	new file:   ORG/DM_TD_EXT_CHPA_ORG.sql
	new file:   ORG/DM_TD_EXT_COUNTY_ORG.sql
	new file:   ORG/DM_TD_EXT_EC_ORG.sql
	new file:   ORG/DM_TD_EXT_RETAIL_ORG.sql
	new file:   ORG/DM_TD_EXT_THC_ORG.sql
	new file:   ORG/DM_TD_EXT_XIEHE_ORG.sql
	new file:   OTHERS/01 dm_td_report_url.sql
	new file:   OTHERS/02 dws_ext_email_warning.sql
	new file:   OTHERS/external_triggered_email.py
	new file:   Retail/01 load_tmp_data.py
	new file:   Retail/02 split_brand_data.py
	new file:   Retail/03 split_pack_data.py
	new file:   Retail/04 map_to_dws_table.py
	new file:   Retail/05 load_dtp_temp_data.py
	new file:   Retail/06 split_dtp_brand_data.py
	new file:   Retail/07 split_dtp_pack_data.py
	new file:   Retail/08 map_to_dtp_dws_table.py
	new file:   Retail/09 dwd_inc_gnd_ext_retail_nataional.py
	new file:   Retail/10 map_to_retail_dm_table.py
	new file:   Retail/11 map_to_overview_dm_table.py
	new file:   Retail/12 dws_tf_external_retail_dtp_special.sql
	new file:   Retail/13 DM_TF_EXT_RETAIL_SALES.sql
	new file:   Retail/14 DM_TF_EXT_RETAIL_DTP_SALES.sql
	new file:   Retail/15 DM_TD_EXT_RETAIL_PACK_PROPERTY.sql
	new file:   Retail/16 DM_TD_EXT_RETAIL_DTP_PACK_PROPERTY.sql
	new file:   Retail/17 DM_TD_EXT_DTP_PACK2MARKET.sql
	new file:   Retail/17 DM_TD_EXT_RETAIL_PACK2MARKET.sql
	new file:   Retail/18 DM_TD_EXT_DTP_MARKET_RATIO.sql
	new file:   Retail/18 DM_TD_EXT_RETAIL_MARKET_RATIO.sql
	new file:   Retail/19 DM_TD_EXT_DTP_MARKET_BRAND_RATIO.sql
	new file:   Retail/19 DM_TD_EXT_RETAIL_MARKET_BRAND_RATIO.sql
	new file:   Retail/20 DM_TD_EXT_DTP_MARKET_PACK_MAPPING.sql
	new file:   Retail/20 DM_TD_EXT_RETAIL_MARKET_PACK_MAPPING.sql
	new file:   "Retail/z1 dwd_inc_gnd_ext_retail_nataional_\344\275\234\345\272\237.py"
	new file:   "Retail/z2 retail_load_data_\344\275\234\345\272\237.sql"
	new file:   "Retail/z3 retail_overview_data_\344\275\234\345\272\237.sql"
	new file:   THC/01 dm_thc_pack_property.sql
	new file:   THC/02 dm_ext_thc_sales.sql
	new file:   THC/02 dm_ext_thc_sales_bakup_20260327.sql
	new file:   THC/03 DM_TF_EXT_THC_MARKET_SALES_CHT.sql
	new file:   THC/04 dm_tf_external_sales_thc.sql
	new file:   THC/05 DM_TD_EXT_THC_PACK_PROPERTY.sql
	new file:   THC/06 DM_TD_EXT_THC_PACK2MARKET.sql
	new file:   THC/07 DM_TD_EXT_THC_MARKET_RATIO.sql
	new file:   THC/08 DM_TD_EXT_THC_MARKET_BRAND_RATIO.sql
	new file:   THC/09 DM_TD_EXT_THC_MARKET_PACK_MAPPING.sql
	new file:   UNIONALL/DM_TD_EXT_UNIONALL_MARKET_PACK_MAPPING.sql
	new file:   UNIONALL/DM_TD_EXT_UNIONALL_PACKINFO.sql
	new file:   UNIONALL/DM_TF_EXT_UNIONALL_MARKET_SALES.sql
	new file:   UNIONALL/DM_TF_EXT_UNIONALL_MARKET_SALES_v1.0.sql
	new file:   UNIONALL/DM_TF_EXT_UNIONALL_SALES.sql
	new file:   UNIONALL/DM_TF_EXT_UNIONALL_SALES_MAPPING.sql
	new file:   UNIONALL/DM_TF_EXT_UNIONALL_SALES_MAPPING_NIAD.sql
	new file:   XIEHE/01 xiehe_blob_to_dwd.py
	new file:   XIEHE/02 dm_xiehe_pack_property.sql
	new file:   XIEHE/03 dm_ext_xiehe_geo.sql
	new file:   XIEHE/04 dm_ext_xiehe_sales.sql
	new file:   XIEHE/05 dm_td_xiehe_core_dept.sql
	new file:   XIEHE/06 DM_TF_EXT_XIEHE_SALES.sql
	new file:   XIEHE/07 DM_TD_EXT_XIEHE_PACK_PROPERTY.sql
	new file:   XIEHE/08 DM_TD_EXT_XIEHE_PACK2MARKET.sql
	new file:   XIEHE/09 DM_TD_EXT_XIEHE_MARKET_RATIO.sql
	new file:   XIEHE/10 DM_TD_EXT_XIEHE_MARKET_BRAND_RATIO.sql
	new file:   XIEHE/11 DM_TD_EXT_XIEHE_MARKET_PACK_MAPPING.sql
	new file:   XIEHE/bkp_01 xiehe_blob2dwd.py
	new file:   XIEHE/bkp_02 dm_ext_xiehe_sales.sql
	new file:   XIEHE/bkp_03 dm_ext_xiehe_pack_property.sql
	new file:   county/01 tmp_ims_county_fact_sales_sum.sql
	new file:   county/02 tmp_imscounty_Result.sql
	new file:   county/03 dm_ims_td_county_geo.sql
	new file:   county/04 dws_ext_county_tf_sales.sql
	new file:   county/05 dm_ext_county_td_pack_property.sql
	new file:   county/06 dm_td_county_pack_region.sql
	new file:   county/07 dm_ext_county_tf_sales_region.sql
	new file:   county/08 DM_TD_EXT_COUNTY_PACK_PROPERTY.sql
	new file:   county/09 DM_TF_EXT_COUNTY_SALES.sql
	new file:   county/10 DM_TD_EXT_COUNTY_PACK2MARKET.sql
	new file:   county/11 DM_TD_EXT_COUNTY_MARKET_RATIO.sql
	new file:   county/12 DM_TD_EXT_COUNTY_MARKET_BRAND_RATIO.sql
	new file:   county/13 DM_TD_EXT_COUNTY_MARKET_PACK_MAPPING.sql
	new file:   for_AIA_Dashboard/01 dm_td_aia_inst_mkt.sql
	new file:   for_AIA_Dashboard/02 dm_td_aia_auth_sales.sql
	new file:   for_AIA_Dashboard/03 dm_td_aia_original_col.sql
	new file:   for_AIA_Dashboard/04 dm_td_aia_nosales_inst.sql
	new file:   for_AIA_Dashboard/05 dm_td_aia_is_eagle_flag.sql
	new file:   for_AIA_Dashboard/06 dm_td_aia_rank.sql
	new file:   for_AIA_Dashboard/07 dm_ext_aia_data_remove_flag.sql
	new file:   for_AIA_Dashboard/07 dm_td_aia_remove_special_ins_bkp.py
	new file:   for_AIA_Dashboard/08 dm_ext_aia_data_quality_flag.sql
	new file:   z 01 dm_tf_external_sales.sql
	new file:   "z 10 dm_td_external_market_pack_mapping_\344\275\234\345\272\237.sql"
	new file:   "z 11 dm_td_external_market_\344\275\234\345\272\237.sql"
	new file:   "\344\270\212\347\272\277\350\204\232\346\234\254.sql"
	new file:   "\346\225\260\346\215\256\351\252\214\350\257\201.sql"
2026-04-27 15:48:38 +08:00

65 lines
4.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Databricks notebook source
-------------------------------------county新倒减拆分需求代码示例之KPI递减-------------------------------------
insert overwrite table tmp.tmp_imscounty_Result
with ObuEast5 as (
--取OBU 东五的数据仅包含L01+L02
SELECT YYYYMM,region_cod,pack_cod,SalesValue_LC,SalesValue_LC_LY,Counting_Unit,Counting_Unit_LY,Sales_Unit,Sales_Unit_LY
FROM tmp.tmp_ims_county_fact_sales_sum
WHERE region_cod = 'County2'
),CountyProv as (
--得到省份的数据
SELECT YYYYMM,region_cod,pack_cod,SalesValue_LC,SalesValue_LC_LY,Counting_Unit,Counting_Unit_LY,Sales_Unit,Sales_Unit_LY
FROM tmp.tmp_ims_county_fact_sales_sum
WHERE region_cod NOT IN ('County','County2','National')
)
,CountyProvSH as (
--取河南、四川的数据(肿瘤+非肿瘤)
SELECT YYYYMM,pack_cod,SUM(Counting_Unit) Counting_Unit,sum(Counting_Unit_LY) Counting_Unit_LY,SUM(Sales_Unit) Sales_Unit,sum(Sales_Unit_LY) Sales_Unit_LY,SUM(SalesValue_LC) SalesValue_LC,sum(SalesValue_LC_LY) SalesValue_LC_LY
FROM CountyProv
WHERE region_cod IN ('Sichuan','Henan')
GROUP BY YYYYMM,pack_cod
),BBU_Other as (
--减去重复的四川河南部分的BBU County数据即可得到BBU Others数据
--BBU County = BBU_OtherProv+四川+河南(肿瘤+非肿瘤产品)
SELECT A.YYYYMM,'BBU_OtherProv' region_cod,A.pack_cod,A.Counting_Unit-NVL(B.Counting_Unit,0) Counting_Unit,A.Counting_Unit_LY-NVL(B.Counting_Unit_LY,0) Counting_Unit_LY,
A.Sales_Unit-NVL(B.Sales_Unit,0) Sales_Unit, A.Sales_Unit_LY-NVL(B.Sales_Unit_LY,0) Sales_Unit_LY,A.SalesValue_LC-NVL(B.SalesValue_LC,0) SalesValue_LC,A.SalesValue_LC_LY-NVL(B.SalesValue_LC_LY,0) SalesValue_LC_LY
FROM tmp.tmp_ims_county_fact_sales_sum A
LEFT JOIN CountyProvSH B ON A.YYYYMM = B.YYYYMM AND
A.pack_cod = B.pack_cod
WHERE A.region_cod = 'County'
),CountyProvOthers_tmp as (
--取山东、江苏、浙江、广东四省数据
SELECT YYYYMM,pack_cod,SUM(Counting_Unit) Counting_Unit,sum(Counting_Unit_LY) Counting_Unit_LY,SUM(Sales_Unit) Sales_Unit,sum(Sales_Unit_LY) Sales_Unit_LY,SUM(SalesValue_LC) SalesValue_LC,sum(SalesValue_LC_LY) SalesValue_LC_LY
FROM CountyProv
WHERE region_cod IN ('Shandong','Jiangsu','Zhejiang','Guangdong')
GROUP BY YYYYMM,pack_cod
),CountyProvFJ as (
--通过OBU东五的数据倒减四省数据得到福建省的数据
SELECT A.YYYYMM, 'OBU_OtherProv' region_cod,A.pack_cod,A.Counting_Unit-NVL(B.Counting_Unit,0) Counting_Unit,A.Counting_Unit_LY-NVL(B.Counting_Unit_LY,0) Counting_Unit_LY,
A.Sales_Unit-NVL(B.Sales_Unit,0) Sales_Unit, A.Sales_Unit_LY-NVL(B.Sales_Unit_LY,0) Sales_Unit_LY,A.SalesValue_LC-NVL(B.SalesValue_LC,0) SalesValue_LC,A.SalesValue_LC_LY-NVL(B.SalesValue_LC_LY,0) SalesValue_LC_LY
FROM ObuEast5 A
LEFT JOIN CountyProvOthers_tmp B ON A.YYYYMM = B.YYYYMM AND A.pack_cod = B.pack_cod
),Result_NonOthers as (
--汇总省份+BBU other+obu otter
SELECT YYYYMM,region_cod,pack_cod,SalesValue_LC,SalesValue_LC_LY,Counting_Unit,Counting_Unit_LY,Sales_Unit,Sales_Unit_LY
FROM CountyProv
UNION ALL
SELECT YYYYMM,region_cod,pack_cod,SalesValue_LC,SalesValue_LC_LY,Counting_Unit,Counting_Unit_LY,Sales_Unit,Sales_Unit_LY
FROM CountyProvFJ
UNION ALL
SELECT YYYYMM,region_cod,pack_cod,SalesValue_LC,SalesValue_LC_LY,Counting_Unit,Counting_Unit_LY,Sales_Unit,Sales_Unit_LY
FROM BBU_Other
),Result_NonOthersGroup AS (
--用于全国产品数据倒减得到other省份数据
SELECT YYYYMM,pack_cod,SUM(Counting_Unit) Counting_Unit,sum(Counting_Unit_LY) Counting_Unit_LY,SUM(Sales_Unit) Sales_Unit,sum(Sales_Unit_LY) Sales_Unit_LY,SUM(SalesValue_LC) SalesValue_LC,sum(SalesValue_LC_LY) SalesValue_LC_LY
FROM Result_NonOthers
GROUP BY YYYYMM,pack_cod
)
SELECT YYYYMM,region_cod,pack_cod,SalesValue_LC,SalesValue_LC_LY,Counting_Unit,Counting_Unit_LY,Sales_Unit,Sales_Unit_LY
FROM Result_NonOthers
UNION ALL
SELECT A.YYYYMM,'Others' region_cod,A.pack_cod,A.SalesValue_LC-NVL(B.SalesValue_LC,0) SalesValue_LC,A.SalesValue_LC_LY-NVL(B.SalesValue_LC_LY,0) SalesValue_LC_LY,A.Counting_Unit-NVL(B.Counting_Unit,0) Counting_Unit,A.Counting_Unit_LY-NVL(B.Counting_Unit_LY,0) Counting_Unit_LY,
A.Sales_Unit-NVL(B.Sales_Unit,0) Sales_Unit, A.Sales_Unit_LY-NVL(B.Sales_Unit_LY,0) Sales_Unit_LY
FROM (SELECT * from tmp.tmp_ims_county_fact_sales_sum WHERE region_cod = 'National') A
LEFT JOIN Result_NonOthersGroup B ON A.YYYYMM = B.YYYYMM AND A.pack_cod = B.pack_cod