diff --git a/county/01 dm_county_pack_property.sql b/county/01 dm_county_pack_property.sql new file mode 100644 index 0000000..bbabd77 --- /dev/null +++ b/county/01 dm_county_pack_property.sql @@ -0,0 +1,223 @@ +-- Databricks notebook source +-- CREATE or replace TABLE dm.dm_county_pack_property ( +-- PACK_COD STRING, +-- pack_des STRING, +-- stgh_des STRING, +-- pack_lch STRING, +-- PROD_COD STRING, +-- prod_des STRING, +-- prod_des_c STRING, +-- Family_Code STRING, +-- Family_Name STRING, +-- cmps_cod STRING, +-- cmps_des STRING, +-- cmps_des_c STRING, +-- atc1_cod STRING, +-- atc1_des STRING, +-- atc1_des_c STRING, +-- atc2_cod STRING, +-- atc2_des STRING, +-- atc2_des_c STRING, +-- atc3_cod STRING, +-- atc3_des STRING, +-- atc3_des_c STRING, +-- atc4_cod STRING, +-- atc4_des STRING, +-- atc4_des_c STRING, +-- app1_cod STRING, +-- app1_des STRING, +-- app1_des_c STRING, +-- app2_cod STRING, +-- app2_des STRING, +-- app2_des_c STRING, +-- app3_cod STRING, +-- app3_des STRING, +-- app3_des_c STRING, +-- bio_desc STRING, +-- gene_orig_desc STRING, +-- eth_otc_desc STRING, +-- nrdl_desc STRING, +-- NRDL_Entry_Date STRING, +-- edl_desc STRING, +-- tcm_desc STRING, +-- paed_desc STRING, +-- gqce_desc STRING, +-- vbp_desc STRING, +-- manu_cod STRING, +-- manu_des STRING, +-- manu_des_c STRING, +-- mnfl_cod STRING, +-- mnfl_des STRING, +-- corp_cod STRING, +-- corp_des STRING, +-- corp_des_c STRING, +-- BrandType STRING, +-- IS_AZ STRING, +-- AZ_MAIN STRING, +-- AZ_Related STRING, +-- countingunit STRING, +-- ETL_INSERT_DT TIMESTAMP, +-- ETL_UPDATE_DT TIMESTAMP) +-- USING delta +-- -- LOCATION 'abfss://master@azcdatalakeprd.dfs.core.chinacloudapi.cn/DM/dm_county_pack_property'; +-- -- 上面是生产环境location,下面是测试环境location +-- LOCATION 'abfss://master@retaildlstoragetest.dfs.core.chinacloudapi.cn/DM/dm_county_pack_property'; + + +-- COMMAND ---------- + +create or replace temporary view dwd_pack_property +as +select distinct + iqvia_pack_code , + iqvia_prod_code , + pack_cod , + 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 , + -- builtinarchivedate , + source_file_path , + source_file_name , + etl_insert_dt , + countingunit +from dwd.dwd_gnd_dept_pack_property + +-- COMMAND ---------- + +insert overwrite table dm.dm_county_pack_property +WITH dedup_l AS ( + SELECT *, + ROW_NUMBER() OVER (PARTITION BY iqvia_pack_code ORDER BY iqvia_pack_code) AS rn + FROM dwd_pack_property + QUALIFY rn = 1 +), +dedup_r AS ( + SELECT *, + ROW_NUMBER() OVER (PARTITION BY PACK_COD ORDER BY PACK_COD) AS rn + FROM tmp.tmp_ext_chpa_pack_propetry + QUALIFY rn = 1 +) +SELECT + l.iqvia_pack_code AS PACK_COD, + + -- Pack / Product 描述 + COALESCE(r.PACK_DES, l.pack_des) AS pack_des, + COALESCE(r.STGH_DES, l.stgh_des) AS stgh_des, + COALESCE(r.PACK_LCH, l.pack_lch) AS pack_lch, + COALESCE(r.PROD_COD, l.iqvia_prod_code) AS PROD_COD, + COALESCE(r.PROD_DES, l.prod_des) AS prod_des, + COALESCE(r.PROD_DES_C, l.prod_des_c) AS prod_des_c, + + -- 右表独有:Family + r.Family_Code, + r.Family_Name, + + -- 成分 + COALESCE(r.CMPS_COD, l.cmps_cod) AS cmps_cod, + COALESCE(r.CMPS_DES, l.cmps_des) AS cmps_des, + COALESCE(r.CMPS_DES_C, l.cmps_des_c) AS cmps_des_c, + + -- ATC + COALESCE(r.ATC1_COD, l.atc1_cod) AS atc1_cod, + COALESCE(r.atc1_des, l.atc1_des) AS atc1_des, + COALESCE(r.atc1_des_c, l.atc1_des_c) AS atc1_des_c, + COALESCE(r.ATC2_COD, l.atc2_cod) AS atc2_cod, + COALESCE(r.atc2_des, l.atc2_des) AS atc2_des, + COALESCE(r.atc2_des_c, l.atc2_des_c) AS atc2_des_c, + COALESCE(r.ATC3_COD, l.atc3_cod) AS atc3_cod, + COALESCE(r.atc3_des, l.atc3_des) AS atc3_des, + COALESCE(r.atc3_des_c, l.atc3_des_c) AS atc3_des_c, + COALESCE(r.ATC4_COD, l.atc4_cod) AS atc4_cod, + COALESCE(r.atc4_des, l.atc4_des) AS atc4_des, + COALESCE(r.atc4_des_c, l.atc4_des_c) AS atc4_des_c, + + -- APP + COALESCE(r.APP1_COD, l.app1_cod) AS app1_cod, + COALESCE(r.app1_des, l.app1_des) AS app1_des, + COALESCE(r.app1_des_c, l.app1_des_c) AS app1_des_c, + COALESCE(r.APP2_COD, l.app2_cod) AS app2_cod, + COALESCE(r.app2_des, l.app2_des) AS app2_des, + COALESCE(r.app2_des_c, l.app2_des_c) AS app2_des_c, + COALESCE(r.APP3_COD, l.app3_cod) AS app3_cod, + COALESCE(r.app3_des, l.app3_des) AS app3_des, + COALESCE(r.app3_des_c, l.app3_des_c) AS app3_des_c, + + -- 标志位 + COALESCE(r.BIO_DESC, l.bio_desc) AS bio_desc, + COALESCE(r.GENE_ORIG_DESC, l.gene_orig_desc) AS gene_orig_desc, + COALESCE(r.ETH_OTC_DESC, l.eth_otc_desc) AS eth_otc_desc, + COALESCE(r.NRDL_DESC, l.nrdl_desc) AS nrdl_desc, + r.NRDL_Entry_Date, + COALESCE(r.EDL_DESC, l.edl_desc) AS edl_desc, + COALESCE(r.TCM_DESC, l.tcm_desc) AS tcm_desc, + COALESCE(r.PAED_DESC, l.paed_desc) AS paed_desc, + COALESCE(r.GQCE_DESC, l.gqce_desc) AS gqce_desc, + COALESCE(r.VBP_DESC, l.vbp_desc) AS vbp_desc, + + -- 厂商 + COALESCE(r.MANU_COD, l.manu_cod) AS manu_cod, + COALESCE(r.MANU_DES, l.manu_des) AS manu_des, + COALESCE(r.MANU_DES_C, l.manu_des_c) AS manu_des_c, + COALESCE(r.MNFL_COD, l.mnfl_cod) AS mnfl_cod, + COALESCE(r.MNFL_DES, l.mnfl_des) AS mnfl_des, + + -- 公司 + COALESCE(r.CORP_COD, l.corp_cod) AS corp_cod, + COALESCE(r.CORP_DES, l.corp_des) AS corp_des, + COALESCE(r.CORP_DES_C, l.corp_des_c) AS corp_des_c, + + -- 右表独有:品牌 / AZ 标志 + r.BrandType, + r.IS_AZ, + r.AZ_MAIN, + r.AZ_Related, + -- 左表独有 + l.countingunit, + from_utc_timestamp(current_timestamp(),'UTC+8') as ETL_INSERT_DT, + from_utc_timestamp(current_timestamp(),'UTC+8') as ETL_UPDATE_DT +FROM dedup_l l +LEFT JOIN dedup_r r + ON l.iqvia_pack_code = r.PACK_COD diff --git a/county/01 tmp_ims_county_fact_sales_sum.sql b/county/01 tmp_ims_county_fact_sales_sum.sql deleted file mode 100644 index c544c56..0000000 --- a/county/01 tmp_ims_county_fact_sales_sum.sql +++ /dev/null @@ -1,60 +0,0 @@ --- Databricks notebook source ---笛卡尔积生成PKAU维度表 -insert overwrite table tmp.tmp_ims_county_pack_audit -SELECT - PACK.Pack_ID, - if( Pack_Code REGEXP '^[0-9]',right(concat('000000000000',Pack_Code),12),Pack_Code) as PACK_CODE,--RIGHT(concat('0000000',Pack_Code),7) - AUDI.Audit_ID, - AUDI.Audit_Name AS AUDIT_COD, - concat(REPLACE(AUDI.Audit_Name,' ','') , '_', if( Pack_Code REGEXP '^[0-9]',right(concat('000000000000',Pack_Code),12),Pack_Code))as PKAU_INDEX, - from_utc_timestamp(current_timestamp,'UTC+8') as etl_insert_dt, - from_utc_timestamp(current_timestamp,'UTC+8') as etl_update_dt -FROM dwd.dwd_gnd_county_dim_pack PACK -CROSS JOIN ( - SELECT - Audit_ID, - Audit_Type, - Audit_Name - FROM dwd.dwd_gnd_county_dim_audit -) AUDI - --- COMMAND ---------- - ----------------------------------------------事实表添加lastyear的KPI字段--------------------------------------------- -insert overwrite table tmp.tmp_ims_county_fact_sales_sum -select -distinct -t1.qtr -,left(t1.qtr,4)*100+right(t1.qtr,1)*3 as yyyymm -,t2.pack_code as pack_cod -,t2.audit_cod as region_cod -,sum(SalesValue_LC ) as SalesValue_LC -,sum(SalesValue_LC_LY) as SalesValue_LC_LY -,sum(Counting_Unit ) as Counting_Unit -,sum(Counting_Unit_LY) as Counting_Unit_LY -,sum(Sales_Unit ) as Sales_Unit -,sum(Sales_Unit_LY) as Sales_Unit_LY -,from_utc_timestamp(current_timestamp,'UTC+8') as etl_insert_dt -,from_utc_timestamp(current_timestamp,'UTC+8') as etl_update_dt -from( - select DISTINCT left(concat(year,'Q',month/3),6) as qtr,pack_id,audit_id, - nvl(SalesValue_LC,0) AS SalesValue_LC, - 0 AS SalesValue_LC_LY, - nvl(Counting_Unit,0) AS Counting_Unit, - 0 AS Counting_Unit_LY, - nvl(Sales_Unit,0) AS Sales_Unit, - 0 AS Sales_Unit_LY - from dwd.dwd_gnd_county_fact_sales - union all - select DISTINCT left(concat(left(year,4),'Q',month/3),6) as qtr,pack_id,audit_id, - 0 AS SalesValue_LC, - nvl(SalesValue_LC,0) AS SalesValue_LC_LY, - 0 AS Counting_Unit, - nvl(Counting_Unit,0) AS Counting_Unit_LY, - 0 AS Sales_Unit, - nvl(Sales_Unit,0) AS Sales_Unit_LY - from (select DISTINCT year+1 as year,month,SalesValue_LC,Counting_Unit,Sales_Unit,pack_id,audit_id from dwd.dwd_gnd_county_fact_sales) fact_ly - where year*100+month in (select distinct year*100+month from dwd.dwd_gnd_county_fact_sales) -)t1 -left join tmp.tmp_ims_county_pack_audit t2 on t1.pack_id=t2.pack_id and t1.audit_id=t2.audit_id -group by t1.qtr,t2.pack_code,t2.audit_cod diff --git a/county/02 dm_td_ext_county_geo_mapping_flag.sql b/county/02 dm_td_ext_county_geo_mapping_flag.sql new file mode 100644 index 0000000..c0c82a9 --- /dev/null +++ b/county/02 dm_td_ext_county_geo_mapping_flag.sql @@ -0,0 +1,23 @@ +-- Databricks notebook source +-- create or replace table dwd.dwd_gnd_county_geo_mapping +-- ( +-- province string, +-- bbu_bu_county_flag string +-- ) +-- location 'abfss://master@retaildlstoragetest.dfs.core.chinacloudapi.cn/DWD/dwd_gnd_county_geo_mapping' + +-- COMMAND ---------- + +-- create or replace table dm.dm_td_ext_county_geo_mapping_flag +-- ( +-- province string, +-- bbu_bu_county_flag string +-- ) +-- USING delta +-- -- location 'abfss://master@azcdatalakeprd.dfs.core.chinacloudapi.cn/DM/dm_td_ext_county_geo_mapping_flag' +-- location 'abfss://master@retaildlstoragetest.dfs.core.chinacloudapi.cn/DM/dm_td_ext_county_geo_mapping_flag' + +-- COMMAND ---------- + +insert overwrite dm.dm_td_ext_county_geo_mapping_flag +select province,bbu_bu_county_flag from dwd.dwd_gnd_county_geo_mapping diff --git a/county/02 tmp_imscounty_Result.sql b/county/02 tmp_imscounty_Result.sql deleted file mode 100644 index 659b4e2..0000000 --- a/county/02 tmp_imscounty_Result.sql +++ /dev/null @@ -1,64 +0,0 @@ --- 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 diff --git a/county/03 DM_TF_EXT_COUNTY_SALES.sql b/county/03 DM_TF_EXT_COUNTY_SALES.sql new file mode 100644 index 0000000..ac6832a --- /dev/null +++ b/county/03 DM_TF_EXT_COUNTY_SALES.sql @@ -0,0 +1,313 @@ +-- Databricks notebook source +-- CREATE OR REPLACE TABLE DM.DM_TF_EXT_COUNTY_SALES ( +-- YYYYMM STRING, +-- PACK_CODE STRING, +-- CORP_CODE STRING, +-- AUDIT_CODE STRING, +-- PLATFORM_TYPE STRING, +-- STORE_NAME STRING, +-- STORE_TYPE STRING, +-- REGION_TYPE STRING, +-- PACK_FLAG INT, +-- PROD_FLAG INT, +-- DTP_FLAG INT, +-- SALES_UNIT_CAL DECIMAL(38,10), +-- SALES_UNIT_CAL_LY DECIMAL(38,10), +-- SALES_VALUE_CAL DECIMAL(38,10), +-- SALES_VALUE_CAL_LY DECIMAL(38,10), +-- CONUTING_UNIT DECIMAL(38,10), +-- CONUTING_UNIT_LY DECIMAL(38,10), +-- DATA_SOURCE STRING, +-- INST_CODE STRING COMMENT '内部机构编码', +-- CMPS_FLAG STRING COMMENT '分子式标签', +-- DEPT_NAME STRING COMMENT '科室名称', +-- PRESCRIPTION DECIMAL(38,10) COMMENT '处方张数', +-- PRESCRIPTION_LY DECIMAL(38,10) COMMENT '去年同期处方张数', +-- NEW_CODE STRING COMMENT '主数据关联CODE', +-- AREA STRING COMMENT '城市', +-- H_LEVEL STRING COMMENT '医院类型', +-- REIMBURSE STRING COMMENT '报销情况', +-- REIMBURSE_TYPE STRING COMMENT '报销类型', +-- PRESCRIPTION_SOURCE STRING COMMENT '处方来源', +-- ETL_INSERT_DT TIMESTAMP, +-- ETL_UPDATE_DT TIMESTAMP) +-- USING delta +-- -- LOCATION 'abfss://master@azcdatalakeprd.dfs.core.chinacloudapi.cn/DM/dm_tf_ext_county_sales'; +-- -- 上面是生产环境location,下面是测试环境location +-- LOCATION 'abfss://master@retaildlstoragetest.dfs.core.chinacloudapi.cn/DM/dm_tf_ext_county_sales'; + + +-- CREATE OR REPLACE TABLE catalog_e2_ngbi_qas.dwd.dwd_gnd_county_pharbers_prov_fact ( +-- year STRING, +-- ym STRING, +-- province_c STRING, +-- ims_drug_id STRING, +-- is_hosp_code STRING, +-- prod_corp STRING, +-- prod_cod STRING, +-- pack_cod STRING, +-- phcd STRING, +-- prod_des STRING, +-- cmps_cod STRING, +-- cmps_des STRING, +-- corp_cod STRING, +-- corp_des STRING, +-- mnfl_cod STRING, +-- prod_des_c STRING, +-- cmps_c STRING, +-- corp_des_c STRING, +-- pack_des STRING, +-- spec STRING, +-- conversion_ratio STRING, +-- dosage_form STRING, +-- atc4_cod STRING, +-- app1_cod STRING, +-- app1_des STRING, +-- app1_des_c STRING, +-- app2_cod STRING, +-- app2_des STRING, +-- app2_des_c STRING, +-- app3_cod STRING, +-- app3_des STRING, +-- app3_des_c STRING, +-- vbp_batch STRING, +-- vbp STRING, +-- value STRING, +-- totalunit STRING, +-- countingunit STRING, +-- price STRING, +-- manu_cod STRING, +-- manu_des STRING, +-- manu_des_c STRING, +-- source_file_path STRING, +-- source_file_name STRING, +-- etl_insert_dt STRING) +-- USING delta +-- LOCATION 'abfss://master@retaildlstoragetest.dfs.core.chinacloudapi.cn/DWD/dwd_gnd_county_pharbers_prov_fact' + + +-- COMMAND ---------- + +-- DBTITLE 1,dwd sales +CREATE OR REPLACE TEMPORARY VIEW FACT_COUNTY_PREVIOUS +AS +SELECT + CAST(YM AS INT) AS YM, + CAST(YEAR AS INT) AS YEAR, + CAST(REPLACE(YM,YEAR,'') AS INT) AS MONTH, + CAST(VALUE AS DECIMAL(38,10)) AS VALUE, + CAST(COUNTINGUNIT AS DECIMAL(38,10)) AS COUNTINGUNIT, + CAST(TOTALUNIT AS DECIMAL(38,10)) AS TOTALUNIT, + PROVINCE_C, + PHCD, + conversion_ratio +FROM dwd.dwd_gnd_county_pharbers_prov_fact + +-- COMMAND ---------- + +-- DBTITLE 1,dwd pach2pack +CREATE OR REPLACE TEMPORARY VIEW DIM_PACK_INFO +AS +SELECT + PACK_COD, + MAX(IQVIA_PACK_CODE) AS IQVIA_PACK_CODE, + MAX(countingunit) as COUNTINGUNIT_RATIO +FROM + dwd.dwd_gnd_dept_pack_property +GROUP BY + PACK_COD + +-- COMMAND ---------- + +CREATE OR REPLACE TEMPORARY VIEW DIM_PROVINCE +AS +select + t2.province_code, + CASE + WHEN + t2.province_name + IN ('上海','北京','天津','重庆') + THEN + CONCAT(t2.province_name,'市') + WHEN + t2.province_name + IN ('内蒙古','西藏') + THEN + CONCAT(t2.province_name,'自治区') + WHEN + t2.province_name = '宁夏' + THEN CONCAT(t2.province_name,'回族自治区') + WHEN + t2.province_name = '广西' + THEN CONCAT(t2.province_name,'壮族自治区') + WHEN + t2.province_name = '新疆' + THEN CONCAT(t2.province_name,'维吾尔自治区') + ELSE CONCAT(t2.province_name,'省') + END AS province_name +from dm.dm_td_geography t2 +where t2.geo_key = t2.province_code +and province_name not in ('台湾','澳门','香港') + +-- COMMAND ---------- + + +WITH original_sales AS ( + SELECT /*+ BROADCAST(T2,T3) */ + T1.YM AS YYYYMM, + T2.PROVINCE_CODE AS AUDIT_COD, + T3.IQVIA_PACK_CODE AS PACK_CODE, + T1.VALUE AS SALES_VALUE, + T1.TOTALUNIT AS SALES_UNIT, + T1.COUNTINGUNIT AS COUNTINGUNIT + FROM FACT_COUNTY_PREVIOUS AS T1 + LEFT JOIN DIM_PROVINCE AS T2 ON T1.PROVINCE_C = T2.PROVINCE_NAME + LEFT JOIN DIM_PACK_INFO AS T3 ON T1.PHCD = T3.PACK_COD +) + +SELECT + cy.YYYYMM, + cy.AUDIT_COD, + cy.PACK_CODE, + cy.SALES_VALUE, + cy.SALES_UNIT, + cy.COUNTINGUNIT, + -- 去年同期:YYYYMM 为 6 位整数,减 100 即同月上一年(如 202403 → 202303) + ly.SALES_VALUE AS SALES_VALUE_LY, + ly.SALES_UNIT AS SALES_UNIT_LY, + ly.COUNTINGUNIT AS COUNTINGUNIT_LY +FROM original_sales AS cy +LEFT JOIN original_sales AS ly + ON ly.YYYYMM = cy.YYYYMM - 100 -- 同月去年 + AND ly.AUDIT_COD = cy.AUDIT_COD + AND ly.PACK_CODE = cy.PACK_CODE + +-- COMMAND ---------- + +INSERT OVERWRITE TABLE DM.DM_TF_EXT_COUNTY_SALES ( + YYYYMM, + PACK_CODE, + AUDIT_CODE, + DATA_SOURCE, + SALES_UNIT_CAL, + SALES_UNIT_CAL_LY, + SALES_VALUE_CAL, + SALES_VALUE_CAL_LY, + CONUTING_UNIT, + CONUTING_UNIT_LY, + PRESCRIPTION, + PRESCRIPTION_LY, + PACK_FLAG, + PROD_FLAG, + DTP_FLAG, + CMPS_FLAG, + PLATFORM_TYPE, + STORE_NAME, + STORE_TYPE, + REGION_TYPE, + INST_CODE, + DEPT_NAME, + NEW_CODE, + AREA, + H_LEVEL, + REIMBURSE, + REIMBURSE_TYPE, + PRESCRIPTION_SOURCE, + CORP_CODE, + ETL_INSERT_DT, + ETL_UPDATE_DT +) + +-- ════════════════════════════════════════════ +-- Part 1:省份数据 +-- 20260518 county的省份数据重写 +-- ════════════════════════════════════════════ +WITH original_sales AS ( + SELECT /*+ BROADCAST(T2,T3) */ + T1.YM AS YYYYMM, + T2.PROVINCE_CODE AS AUDIT_COD, + T3.IQVIA_PACK_CODE AS PACK_COD, + T1.VALUE AS SALES_VALUE_CAL, + T1.TOTALUNIT AS SALES_UNIT_CAL, + T1.COUNTINGUNIT AS CONUTING_UNIT + FROM FACT_COUNTY_PREVIOUS AS T1 + LEFT JOIN DIM_PROVINCE AS T2 ON T1.PROVINCE_C = T2.PROVINCE_NAME + LEFT JOIN DIM_PACK_INFO AS T3 ON T1.PHCD = T3.PACK_COD +) + +,formated_count_sales_table ( + SELECT + cy.YYYYMM, + cy.AUDIT_COD, + cy.PACK_COD, + cy.SALES_VALUE_CAL, + cy.SALES_UNIT_CAL, + cy.CONUTING_UNIT, + -- 去年同期:YYYYMM 为 6 位整数,减 100 即同月上一年(如 202403 → 202303) + ly.SALES_VALUE_CAL AS SALES_VALUE_CAL_LY, + ly.SALES_UNIT_CAL AS SALES_UNIT_CAL_LY, + ly.CONUTING_UNIT AS CONUTING_UNIT_LY +FROM original_sales AS cy +LEFT JOIN original_sales AS ly + ON ly.YYYYMM = cy.YYYYMM - 100 -- 同月去年 + AND ly.AUDIT_COD = cy.AUDIT_COD + AND ly.PACK_COD = cy.PACK_COD +) + +-- ════════════════════════════════════════════ +-- Part 2:延续合同并表中的结构 +-- 20260518 county的省份数据重写 +-- ════════════════════════════════════════════ + SELECT + A.YYYYMM, + A.PACK_COD AS PACK_CODE, + A.AUDIT_COD AS AUDIT_CODE, + 'IQVIA-COUNTY(Quarterly)' DATA_SOURCE, + ------------------------------------- + SUM(SALES_UNIT_CAL) SALES_UNIT_CAL, + SUM(SALES_UNIT_CAL_LY) as SALES_UNIT_CAL_LY, + SUM(SALES_VALUE_CAL) SALES_VALUE_CAL, + SUM(SALES_VALUE_CAL_LY) as SALES_VALUE_CAL_LY, + SUM(CONUTING_UNIT) CONUTING_UNIT, + SUM(CONUTING_UNIT_LY) as CONUTING_UNIT_LY, + null as prescription, + null as prescription_ly, + ------------------------------------- + --Retail藏数逻辑标签------------------ + 1 PACK_FLAG, + 1 PROD_FLAG, + 0 DTP_FLAG, + null as cmps_flag, + ------------------------------------- + --EC数据标签-------------------------- + '' PLATFORM_TYPE, + '' STORE_NAME, + '' STORE_TYPE, + ------------------------------------- + --COUNTY数据标签---------------------- + '' REGION_TYPE, + ------------------------------------- + --AIA数据标签------------------------- + null inst_code, --可以移除,报告没有使用 + ------------------------------------- + --XIE HE 数据标签--------------------- + '' as dept_name, + '' as new_code, + '' as area, + '' as h_level, + '' as reimburse, + '' as reimburse_type, + '' as prescription_source, + ------------------------------------- + '' as CORP_CODE, --可以移除,报告没有使用 + ------------------------------------- + FROM_UTC_TIMESTAMP(CURRENT_TIMESTAMP(), 'UTC+8') AS ETL_INSERT_DT, + FROM_UTC_TIMESTAMP(CURRENT_TIMESTAMP(), 'UTC+8') AS ETL_UPDATE_DT + FROM + formated_count_sales_table A + where + A.YYYYMM >= '202001' + GROUP BY + A.YYYYMM, + A.PACK_COD, + A.AUDIT_COD diff --git a/county/03 dm_ims_td_county_geo.sql b/county/03 dm_ims_td_county_geo.sql deleted file mode 100644 index 8adad6b..0000000 --- a/county/03 dm_ims_td_county_geo.sql +++ /dev/null @@ -1,24 +0,0 @@ --- Databricks notebook source ------------------------------------------------创建county geo表----------------------------------------------- -insert overwrite table dm.dm_ims_td_county_geo -with geo as ( - select - distinct - REGION_COD -from tmp.tmp_imscounty_Result -) -select distinct -case when A.PROVINCE_CODE is not null then A.PROVINCE_CODE - when A.PROVINCE_CODE is null and geo.REGION_COD = 'Others' then 'ROC' - when A.PROVINCE_CODE is null and geo.REGION_COD = 'OBU_OtherProv' then 'OBUROC' - when A.PROVINCE_CODE is null and geo.REGION_COD = 'BBU_OtherProv' then 'BBUROC' - end AUDIT_COD, -geo.REGION_COD, -nvl(A.PROVINCE_C,geo.REGION_COD ) PROVINCE_C, -nvl(A.PROVINCE_MAP,geo.REGION_COD ) PROVINCE_MAP, -nvl(INITCAP(A.REGION_CENTER),geo.REGION_COD ) REGION_CENTER -from geo -left join (select * from dm.dm_ims_td_geo where PROVINCE_CODE is not null) A -on geo.REGION_COD = A.PROVINCE - - diff --git a/county/08 DM_TD_EXT_COUNTY_PACK_PROPERTY.sql b/county/04 DM_TD_EXT_COUNTY_PACK_PROPERTY.sql similarity index 87% rename from county/08 DM_TD_EXT_COUNTY_PACK_PROPERTY.sql rename to county/04 DM_TD_EXT_COUNTY_PACK_PROPERTY.sql index 2d48521..b5b7236 100644 --- a/county/08 DM_TD_EXT_COUNTY_PACK_PROPERTY.sql +++ b/county/04 DM_TD_EXT_COUNTY_PACK_PROPERTY.sql @@ -1,7 +1,7 @@ -- Databricks notebook source -- CREATE OR REPLACE TABLE DM.DM_TD_EXT_COUNTY_PACK_PROPERTY -- ( --- MARKET_PACK_KEY STRING, +-- -- MARKET_PACK_KEY STRING, -- PACK_CODE STRING, -- PACK_DESC STRING, -- STGH_DESC STRING, @@ -41,11 +41,11 @@ -- CORP_DESC STRING, -- CORP_DESC_C STRING, -- BRANDTYPE STRING, --- MARKET STRING, --- KEY_COMPETITOR STRING, +-- -- MARKET STRING, +-- -- KEY_COMPETITOR STRING, -- IS_AZ STRING, -- AZ_MAIN STRING, --- AZ_RELATED STRING, +-- -- AZ_RELATED STRING, -- ATC1_DESC STRING, -- ATC1_DESC_C STRING, -- ATC2_DESC STRING, @@ -60,8 +60,8 @@ -- APP2_DESC_C STRING, -- APP3_DESC STRING, -- APP3_DESC_C STRING, --- CLASS STRING, --- MARKET_RATIO STRING, +-- -- CLASS STRING, +-- -- MARKET_RATIO STRING, -- COUNTINGUNIT STRING, -- VBP_BRAND STRING, -- REPLENISH_FALG STRING, @@ -75,9 +75,9 @@ -- COMMAND ---------- -INSERT OVERWRITE TABLE DM.DM_TD_EXT_COUNTY_PACK_PROPERTY +INSERT OVERWRITE TABLE DM.DM_TD_EXT_CHC_PACK_PROPERTY SELECT - MARKET_PACK_KEY, + -- MARKET_PACK_KEY, PACK_COD AS PACK_CODE, PACK_DES AS PACK_DESC, STGH_DES AS STGH_DESC, @@ -89,7 +89,7 @@ SELECT PROD_DES_C AS PROD_DESC_C, CMPS_COD AS CMPS_CODE, CMPS_DES AS CMPS_DESC, - NULL AS CMPS_DESC_C, + CMPS_DES_C AS CMPS_DESC_C, ATC1_COD AS ATC1_CODE, ATC2_COD AS ATC2_CODE, ATC3_COD AS ATC3_CODE, @@ -106,22 +106,22 @@ SELECT TCM_DESC, PAED_DESC, GQCE_DESC, - NULL AS VBP_DESC_V, + null as VBP_DESC_V, VBP_DESC, MANU_COD AS MANU_CODE, MANU_DES AS MANU_DESC, - NULL AS MANU_DESC_C, + MANU_DES_C AS MANU_DESC_C, MNFL_COD AS MNFL_CODE, MNFL_DES AS MNFL_DESC, CORP_COD AS CORP_CODE, CORP_DES AS CORP_DESC, CORP_DES_C AS CORP_DESC_C, BRANDTYPE, - MARKET, - KEY_COMPETITOR, + -- MARKET, + -- KEY_COMPETITOR, IS_AZ, AZ_MAIN, - AZ_RELATED, + -- AZ_RELATED, ATC1_DES AS ATC1_DESC, ATC1_DES_C AS ATC1_DESC_C, ATC2_DES AS ATC2_DESC, @@ -136,11 +136,11 @@ SELECT APP2_DES_C AS APP2_DESC_C, APP3_DES AS APP3_DESC, APP3_DES_C AS APP3_DESC_C, - CLASS, - NULL AS MARKET_RATIO, - NULL AS COUNTINGUNIT, + -- CLASS, + -- NULL AS MARKET_RATIO, + COUNTINGUNIT, NULL AS VBP_BRAND, NULL AS REPLENISH_FALG, FROM_UTC_TIMESTAMP(CURRENT_TIMESTAMP(),'UTC+8') AS ETL_INSERT_DT, FROM_UTC_TIMESTAMP(CURRENT_TIMESTAMP(),'UTC+8') AS ETL_UPDATE_DT -FROM DM.DM_EXT_COUNTY_TD_PACK_PROPERTY; \ No newline at end of file +FROM DM.DM_COUNTY_PACK_PROPERTY; diff --git a/county/04 dws_ext_county_tf_sales.sql b/county/04 dws_ext_county_tf_sales.sql deleted file mode 100644 index 290f248..0000000 --- a/county/04 dws_ext_county_tf_sales.sql +++ /dev/null @@ -1,36 +0,0 @@ --- Databricks notebook source ----------------------------------bbu county、obu county拆分需求代码示例之事实表字段开发--------------------------------- -insert overwrite table dws.dws_ext_county_tf_sales -select -distinct -cast(cast(t1.YYYYMM as int) as string) as YYYYMM -,concat(left(cast(t1.YYYYMM as int),4 ),'-',right(cast(t1.YYYYMM as int),2),'-01') as DAY_DATE -,t1.pack_cod as PACK_COD -,t1.region_cod as REGION_COD -,geo.AUDIT_COD -,'ALL' as RELATED_FLAG -,'' as ORG_KEY -,'IMS ALL Market' as MARKET -, concat('IMS ALL Market','_',t1.pack_cod ) as MARKET_PACK_KEY -,'' as MARKET_AUDIT_KEY -,'' as SALES_VALUE -,'' as SALES_VALUE_LY -,'' as SALES_VALUE_L2Y -,'' as SALES_UNIT -,'' as SALES_UNIT_LY -,'' as SALES_UNIT_L2Y -,t1.Counting_Unit as CONUTING_UNIT -,t1.Counting_Unit_LY as CONUTING_UNIT_LY -,'' as CONUTING_UNIT_L2Y -,t1.Counting_Unit as PDOT -,'' as PDOT_LY -,'' as PDOT_L2Y -,t1.SalesValue_LC as SALES_VALUE_CAL -,t1.SalesValue_LC_LY as SALES_VALUE_CAL_LY -,t1.Sales_Unit as SALES_UNIT_CAL -,t1.Sales_Unit_LY as SALES_UNIT_CAL_LY -,from_utc_timestamp(current_timestamp,'UTC+8') as etl_insert_dt -,from_utc_timestamp(current_timestamp,'UTC+8') as etl_update_dt -from tmp.tmp_imscounty_Result t1 -left join dm.dm_ims_td_county_geo geo -on t1.region_cod = geo.REGION_COD diff --git a/county/05 dm_ext_county_td_pack_property.sql b/county/05 dm_ext_county_td_pack_property.sql deleted file mode 100644 index a914f2f..0000000 --- a/county/05 dm_ext_county_td_pack_property.sql +++ /dev/null @@ -1,236 +0,0 @@ --- Databricks notebook source --- county 自己的维度表 dm_ext_county_td_pack_property -insert overwrite table dm.dm_ext_county_td_pack_property --------------------------------------------county事实表中与CHPA匹配到的维度信息-------------------------------------------- - with county_matched_value as ( - select - concat(t2.MARKET,t1.PACK_COD) as MARKET_PACK_KEY, - t1.PACK_COD, - t1.PACK_DES, - t1.STGH_DES, - t1.PACK_LCH, - t1.Family_Code, - t1.Family_Name, - t1.PROD_COD, - t1.PROD_DES, - t1.PROD_DES_C, - t1.CMPS_COD, - t1.CMPS_DES, - t1.ATC1_COD, - t1.ATC2_COD, - t1.ATC3_COD, - t1.ATC4_COD, - t1.APP1_COD, - t1.APP2_COD, - t1.APP3_COD, - t1.BIO_DESC, - t1.GENE_ORIG_DESC, - t1.ETH_OTC_DESC, - t1.NRDL_DESC, - t1.NRDL_Entry_Date, - t1.EDL_DESC, - t1.TCM_DESC, - t1.PAED_DESC, - t1.GQCE_DESC, - t1.VBP_DESC, - t1.MANU_COD, - t1.MANU_DES, - t1.MNFL_COD, - t1.MNFL_DES, - t1.CORP_COD, - t1.CORP_DES, - t1.CORP_DES_C, - t1.BrandType, - t2.MARKET, - t2.KEY_COMPETITOR, - t1.IS_AZ, - t1.AZ_MAIN, - null AZ_Related, - t1.atc1_des, - t1.atc1_des_c, - t1.atc2_des, - t1.atc2_des_c, - t1.atc3_des, - t1.atc3_des_c, - t1.atc4_des, - t1.atc4_des_c, - t1.app1_des, - t1.app1_des_c, - t1.app2_des, - t1.app2_des_c, - t1.app3_des, - t1.app3_des_c, - t2.Class, - t1.ETL_INSERT_DT, - t1.ETL_UPDATE_DT - from - dm.dm_ims_td_pack_property t1 -left join DM.DM_TD_EXT_CHPA_MARKET_PACK_MAPPING t2 on t1.PACK_COD = t2.PACK_CODE ---事实表中有yyyymm字段,故要去重,防止数据发散 - - inner join ( - select distinct - PACK_COD - from - dws.dws_ext_county_tf_sales - ) t3 on t1.PACK_COD = t3.PACK_COD - ), - -------------------------------county事实表中与CHPA没有匹配到的维度信息取county维度表里的维度信息------------------------------- - --获取county表与CHPA没有匹配到的MARKET_PACK_KEY - county_notmatched_key as (select - t3.PACK_COD - from - ( - select distinct - PACK_COD - from - dws.dws_ext_county_tf_sales - ) t3 - where - not exists ( - select - 1 - from - dm.dm_ims_td_pack_property t4 - where - t3.PACK_COD = t4.PACK_COD - ) - ), - county_notmatched_value as (--获取county维度表里的维度信息 - select - distinct - t6.MARKET_PACK_KEY, - t6.PACK_COD, - t6.PACK_DES, - t6.STGH_DES, - t6.PACK_LCH, - t6.Family_Code, - t6.Family_Name, - t6.PROD_COD, - t6.PROD_DES, - t6.PROD_DES_C, - t6.CMPS_COD, - t6.CMPS_DES, - t6.ATC1_COD, - t6.ATC2_COD, - t6.ATC3_COD, - t6.ATC4_COD, - t6.APP1_COD, - t6.APP2_COD, - t6.APP3_COD, - t6.BIO_DESC, - t6.GENE_ORIG_DESC, - t6.ETH_OTC_DESC, - t6.NRDL_DESC, - t6.NRDL_Entry_Date, - t6.EDL_DESC, - t6.TCM_DESC, - t6.PAED_DESC, - t6.GQCE_DESC, - t6.VBP_DESC, - t6.MANU_COD, - t6.MANU_DES, - t6.MNFL_COD, - t6.MNFL_DES, - t6.CORP_COD, - t6.CORP_DES, - t6.CORP_DES_C, - t6.BrandType, - t6.MARKET, - t6.KEY_COMPETITOR, - t6.IS_AZ, - t6.AZ_MAIN, - t6.AZ_Related, - t6.atc1_des, - t6.atc1_des_c, - t6.atc2_des, - t6.atc2_des_c, - t6.atc3_des, - t6.atc3_des_c, - t6.atc4_des, - t6.atc4_des_c, - t6.app1_des, - t6.app1_des_c, - t6.app2_des, - t6.app2_des_c, - t6.app3_des, - t6.app3_des_c, - t6.Class, - from_utc_timestamp(current_timestamp, 'UTC+8') ETL_INSERT_DT, - from_utc_timestamp(current_timestamp, 'UTC+8') ETL_UPDATE_DT - from - county_notmatched_key t5 - left join dm.dm_ims_county_td_pack_property t6 --此表有重复数据(etl时间不同) - on t5.PACK_COD = t6.PACK_COD - ), - county_total_pack_property as (select - * - from - county_matched_value - union - select - * - from - county_notmatched_value - ) - select - MARKET_PACK_KEY, - PACK_COD, - PACK_DES, - STGH_DES, - PACK_LCH, - Family_Code, - Family_Name, - PROD_COD, - PROD_DES, - PROD_DES_C, - CMPS_COD, - CMPS_DES, - ATC1_COD, - ATC2_COD, - ATC3_COD, - ATC4_COD, - APP1_COD, - APP2_COD, - APP3_COD, - BIO_DESC, - GENE_ORIG_DESC, - ETH_OTC_DESC, - NRDL_DESC, - NRDL_Entry_Date, - EDL_DESC, - TCM_DESC, - PAED_DESC, - GQCE_DESC, - VBP_DESC, - MANU_COD, - MANU_DES, - MNFL_COD, - MNFL_DES, - CORP_COD, - CORP_DES, - CORP_DES_C, - BrandType, - MARKET, - upper(NVL(KEY_COMPETITOR, 'Others')) as KEY_COMPETITOR, - IS_AZ, - AZ_MAIN, - AZ_Related, - atc1_des, - atc1_des_c, - atc2_des, - atc2_des_c, - atc3_des, - atc3_des_c, - atc4_des, - atc4_des_c, - app1_des, - app1_des_c, - app2_des, - app2_des_c, - app3_des, - app3_des_c, - Class, - ETL_INSERT_DT, - ETL_UPDATE_DT - from - county_total_pack_property \ No newline at end of file diff --git a/county/06 dm_td_county_pack_region.sql b/county/06 dm_td_county_pack_region.sql deleted file mode 100644 index fa14bdd..0000000 --- a/county/06 dm_td_county_pack_region.sql +++ /dev/null @@ -1,106 +0,0 @@ --- Databricks notebook source --- --OBU COUNTY 改为 OBU EAST5、OBU_BU_COUNTY 改为 OBU NON EAST5 --- drop table if exists dm.dm_td_county_pack_region; --- create table if not exists dm.dm_td_county_pack_region --- using delta --- as --- with tmp as ( --- select --- t1.pack_cod, --- t1.region_cod, --- t2.ATC1_COD, --- t2.ATC2_COD --- from (select distinct PACK_COD,REGION_COD from dws.dws_ext_county_tf_sales) t1 --- left join (select distinct PACK_COD,ATC1_COD,ATC2_COD from dm.dm_ext_county_td_pack_property) t2 --- on t1.PACK_COD = t2.pack_cod --- ),obu_county as ( --- select pack_cod,region_cod,'OBU East5' region_type from tmp where region_cod in ('Shandong','Jiangsu','Zhejiang','Guangdong','OBU_OtherProv') and (ATC2_COD = 'L01' OR ATC2_COD = 'L02')--ATC1_COD = 'L' --- ),bbu_county as ( --- select pack_cod,region_cod,'BBU COUNTY' region_type from tmp where region_cod in('Henan','Sichuan','BBU_OtherProv') --- and ATC1_COD <> 'L' --- ),bbu_bu_county as ( --- select pack_cod,region_cod,'BBU_BU_COUNTY' region_type from tmp where region_cod in ('Guangdong','Zhejiang','Shandong','Jiangsu','Others') and ATC1_COD <> 'L' --- ),obu_bu_county as ( --- select pack_cod,region_cod,'OBU NonEast5' region_type from tmp where region_cod in ('Henan','Sichuan','Others','BBU_OtherProv') and (ATC2_COD = 'L01' OR ATC2_COD = 'L02') --- ),county_all as ( --- select * from obu_county --- union --- select * from bbu_county --- union --- select * from bbu_bu_county --- union --- select * from obu_bu_county --- ) --- select --- pack_cod, --- region_cod, --- region_type --- from county_all order by region_type - --- COMMAND ---------- - ----------------------------------------------------------------------------------- ---修改时间:20240913 ---修改人:FanXujia ---修改内容: ---划分BBU_COUNTY、BBU_BU_COUNTY两个区域时,去掉ATC1_COD <> 'L'的限制 ---这个需求使得BBU和OBU会有一部分重叠的区域 ---因此对区域划分逻辑进行调整 ------几个region_cod的含义 ---OBU_OtherProv:福建的ATC2=L01、L02 ---BBU_OtherProv:BBU_COUNTY的18个省减去四川、河南 ---Others:其他省份,这里面包含了福建的ATC2<>L01、L02的数 ----------------------------------------------------------------------------------- -insert overwrite table dm.dm_td_county_pack_region -with tmp as ( - select - t1.pack_cod, - t1.region_cod, - t2.ATC1_COD, - t2.ATC2_COD -from (select distinct PACK_COD,REGION_COD from dws.dws_ext_county_tf_sales) t1 -left join (select distinct PACK_COD,ATC1_COD,ATC2_COD from dm.dm_ext_county_td_pack_property) t2 -on t1.PACK_COD = t2.pack_cod -) ---单独bbu_bu_county -,bbu_bu_county as ( - select pack_cod,region_cod,'BBU_BU_COUNTY' region_type from tmp - where region_cod in ('Guangdong','Jiangsu','Others','Shandong','Zhejiang') and ATC2_COD NOT IN ('L01','L02') -) ---bbu_bu_county与OBU East5共有 -,bbu_bu_county_obu_East5 as ( - select pack_cod,region_cod,'bbu_bu_county_obu_East5' region_type from tmp - where region_cod in ('Guangdong','Jiangsu','Shandong','Zhejiang','OBU_OtherProv') and ATC2_COD in ('L01','L02') -) ---bbu_bu_county与OBU NonEast5共有 -,bbu_bu_county_obu_nonEast5 as ( - select pack_cod,region_cod,'bbu_bu_county_obu_nonEast5' region_type from tmp - where region_cod in ('Others') and ATC2_COD in ('L01','L02') -) ---bbu_county与OBU NonEast5共有 -,bbu_county_obu_nonEast5 as ( - select pack_cod,region_cod,'bbu_county_obu_nonEast5' region_type from tmp - where region_cod in ('BBU_OtherProv','Henan','Sichuan') and ATC2_COD in ('L01','L02') -) ---单独bbu_county -,bbu_county as ( - select pack_cod,region_cod,'BBU County' region_type from tmp - where region_cod in('BBU_OtherProv','Henan','Sichuan') and ATC2_COD NOT IN ('L01','L02') -) ---全部 -,county_all as ( - select * from bbu_bu_county - union - select * from bbu_bu_county_obu_East5 - union - select * from bbu_bu_county_obu_nonEast5 - union - select * from bbu_county_obu_nonEast5 - union - select * from bbu_county -) -select - pack_cod, - region_cod, - region_type -from county_all order by region_type diff --git a/county/07 dm_ext_county_tf_sales_region.sql b/county/07 dm_ext_county_tf_sales_region.sql deleted file mode 100644 index 73ec3f4..0000000 --- a/county/07 dm_ext_county_tf_sales_region.sql +++ /dev/null @@ -1,37 +0,0 @@ --- Databricks notebook source ---county事实表加上region_type字段 -insert overwrite table dm.dm_ext_county_tf_sales_region -select - A.YYYYMM, - A.DAY_DATE, - A.PACK_COD, - A.REGION_COD, - A.AUDIT_COD, - A.RELATED_FLAG, - A.ORG_KEY, - A.MARKET, - A.MARKET_PACK_KEY, - A.MARKET_AUDIT_KEY, - A.SALES_VALUE, - A.SALES_VALUE_LY, - A.SALES_VALUE_L2Y, - A.SALES_UNIT, - A.SALES_UNIT_LY, - A.SALES_UNIT_L2Y, - A.CONUTING_UNIT, - A.CONUTING_UNIT_LY, - A.CONUTING_UNIT_L2Y, - A.PDOT, - A.PDOT_LY, - A.PDOT_L2Y, - A.SALES_VALUE_CAL, - A.SALES_VALUE_CAL_LY, - A.SALES_UNIT_CAL, - A.SALES_UNIT_CAL_LY, - A.etl_insert_dt, - A.etl_update_dt, - B.region_type as REGION_TYPE -from dws.dws_ext_county_tf_sales A -left join dm.dm_td_county_pack_region B -on A.PACK_COD = B.pack_cod and A.REGION_COD = B.region_cod -order by region_type diff --git a/county/09 DM_TF_EXT_COUNTY_SALES.sql b/county/09 DM_TF_EXT_COUNTY_SALES.sql deleted file mode 100644 index da495ff..0000000 --- a/county/09 DM_TF_EXT_COUNTY_SALES.sql +++ /dev/null @@ -1,128 +0,0 @@ --- Databricks notebook source --- CREATE OR REPLACE TABLE DM.DM_TF_EXT_COUNTY_SALES ( --- YYYYMM STRING, --- PACK_CODE STRING, --- CORP_CODE STRING, --- AUDIT_CODE STRING, --- PLATFORM_TYPE STRING, --- STORE_NAME STRING, --- STORE_TYPE STRING, --- REGION_TYPE STRING, --- PACK_FLAG INT, --- PROD_FLAG INT, --- DTP_FLAG INT, --- SALES_UNIT_CAL DECIMAL(38,10), --- SALES_UNIT_CAL_LY DECIMAL(38,10), --- SALES_VALUE_CAL DECIMAL(38,10), --- SALES_VALUE_CAL_LY DECIMAL(38,10), --- CONUTING_UNIT DECIMAL(38,10), --- CONUTING_UNIT_LY DECIMAL(38,10), --- DATA_SOURCE STRING, --- INST_CODE STRING COMMENT '内部机构编码', --- CMPS_FLAG STRING COMMENT '分子式标签', --- DEPT_NAME STRING COMMENT '科室名称', --- PRESCRIPTION DECIMAL(38,10) COMMENT '处方张数', --- PRESCRIPTION_LY DECIMAL(38,10) COMMENT '去年同期处方张数', --- NEW_CODE STRING COMMENT '主数据关联CODE', --- AREA STRING COMMENT '城市', --- H_LEVEL STRING COMMENT '医院类型', --- REIMBURSE STRING COMMENT '报销情况', --- REIMBURSE_TYPE STRING COMMENT '报销类型', --- PRESCRIPTION_SOURCE STRING COMMENT '处方来源', --- ETL_INSERT_DT TIMESTAMP, --- ETL_UPDATE_DT TIMESTAMP) --- USING delta --- -- LOCATION 'abfss://master@azcdatalakeprd.dfs.core.chinacloudapi.cn/DM/dm_tf_ext_county_sales'; --- -- 上面是生产环境location,下面是测试环境location --- LOCATION 'abfss://master@retaildlstoragetest.dfs.core.chinacloudapi.cn/DM/dm_tf_ext_county_sales'; - --- COMMAND ---------- - -INSERT OVERWRITE TABLE DM.DM_TF_EXT_COUNTY_SALES ( - YYYYMM, - PACK_CODE, - AUDIT_CODE, - DATA_SOURCE, - SALES_UNIT_CAL, - SALES_UNIT_CAL_LY, - SALES_VALUE_CAL, - SALES_VALUE_CAL_LY, - CONUTING_UNIT, - CONUTING_UNIT_LY, - PRESCRIPTION, - PRESCRIPTION_LY, - PACK_FLAG, - PROD_FLAG, - DTP_FLAG, - CMPS_FLAG, - PLATFORM_TYPE, - STORE_NAME, - STORE_TYPE, - REGION_TYPE, - INST_CODE, - DEPT_NAME, - NEW_CODE, - AREA, - H_LEVEL, - REIMBURSE, - REIMBURSE_TYPE, - PRESCRIPTION_SOURCE, - CORP_CODE, - ETL_INSERT_DT, - ETL_UPDATE_DT -) - SELECT - A.YYYYMM, - A.PACK_COD AS PACK_CODE, - A.AUDIT_COD AS AUDIT_CODE, - 'IQVIA-COUNTY(Quarterly)' DATA_SOURCE, - ------------------------------------- - SUM(SALES_UNIT_CAL) SALES_UNIT_CAL, - SUM(SALES_UNIT_CAL_LY) as SALES_UNIT_CAL_LY, - SUM(SALES_VALUE_CAL) SALES_VALUE_CAL, - SUM(SALES_VALUE_CAL_LY) as SALES_VALUE_CAL_LY, - SUM(CONUTING_UNIT) CONUTING_UNIT, - SUM(CONUTING_UNIT_LY) as CONUTING_UNIT_LY, - null as prescription, - null as prescription_ly, - ------------------------------------- - --Retail藏数逻辑标签------------------ - 1 PACK_FLAG, - 1 PROD_FLAG, - 0 DTP_FLAG, - null as cmps_flag, - ------------------------------------- - --EC数据标签-------------------------- - '' PLATFORM_TYPE, - '' STORE_NAME, - '' STORE_TYPE, - ------------------------------------- - --COUNTY数据标签---------------------- - NVL(A.REGION_TYPE, '') REGION_TYPE, - ------------------------------------- - --AIA数据标签------------------------- - null inst_code, --可以移除,报告没有使用 - ------------------------------------- - --XIE HE 数据标签--------------------- - '' as dept_name, - '' as new_code, - '' as area, - '' as h_level, - '' as reimburse, - '' as reimburse_type, - '' as prescription_source, - ------------------------------------- - '' as CORP_CODE, --可以移除,报告没有使用 - ------------------------------------- - FROM_UTC_TIMESTAMP(CURRENT_TIMESTAMP(), 'UTC+8') AS ETL_INSERT_DT, - FROM_UTC_TIMESTAMP(CURRENT_TIMESTAMP(), 'UTC+8') AS ETL_UPDATE_DT - FROM - DM.dm_ext_county_tf_sales_region A - where - A.YYYYMM >= '202001' - AND A.MARKET = 'IMS ALL Market' - GROUP BY - A.YYYYMM, - A.PACK_COD, - A.AUDIT_COD, - A.REGION_TYPE \ No newline at end of file diff --git a/county/County_Fact 2.xlsx b/county/County_Fact 2.xlsx deleted file mode 100644 index 53b490a..0000000 Binary files a/county/County_Fact 2.xlsx and /dev/null differ diff --git a/county/County_GEO 4.xlsx b/county/County_GEO 4.xlsx deleted file mode 100644 index cff7316..0000000 Binary files a/county/County_GEO 4.xlsx and /dev/null differ diff --git a/county/New Notebook 2026-05-18 10_46_19.py b/county/New Notebook 2026-05-18 10_46_19.py deleted file mode 100644 index fce9118..0000000 --- a/county/New Notebook 2026-05-18 10_46_19.py +++ /dev/null @@ -1,6 +0,0 @@ -# Databricks notebook source -import pandas as pd - -# COMMAND ---------- - -