update20260427

This commit is contained in:
2026-04-27 11:04:09 +08:00
commit 3e14e78af3
173 changed files with 62579 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
-- Databricks notebook source
-- MAGIC %run ../../../Common/config
-- COMMAND ----------
-- MAGIC %python
-- MAGIC spark.read.table(f'`{CDW_CATALOG}`.`dwd`.`dim_product_wide`').createOrReplaceTempView('cdw_dwd_dim_product_wide')
-- MAGIC spark.read.table(f'`{CDW_CATALOG}`.`dwd`.`dwd_hospital_classification`').createOrReplaceTempView('cdw_dwd_dwd_hospital_classification')
-- COMMAND ----------
--
----------------------------------------------------------------------------------------------------------------------
--修改时间20241029
--FanXujia
--
--12 + 0
--24 + 0
--20222023010
----------------------------------------------------------------------------------------------------------------------
insert overwrite table dm.dm_aia_provided_flag
with max_ym as (
select max(ym) as max_ym
from dm.dm_ext_aia_sales
)
,ym_range as (
select max_ym,
case when max_ym <= '202412' then cast(right(max_ym,2) as int)
else cast(12 as int)
end ym_12m,
case when max_ym <= '202312' then '202401'
when right(max_ym,2) = '12' then concat(left(max_ym,4),'01')
else concat(cast(left(max_ym, 4) - 1 as int),right(concat('0', cast(right(max_ym, 2) + 1 as int)), 2))
end as ym_12m_before,
case when max_ym <= '202312' then cast(right(max_ym,2) as int)
when max_ym <= '202512' then cast(right(max_ym,2) as int) + 12
else cast(24 as int)
end as ym_24m,
case when max_ym <= '202512' then '202401'
when right(max_ym,2) = '12' then concat(cast(left(max_ym,4) - 1 as int),'01')
else concat(cast(left(max_ym, 4) -2 as int),right(concat('0', cast(right(max_ym, 2) + 1 as int)), 2))
end as ym_24m_before
from max_ym
)
,sales_1 as (
select
inst_code,
ym
from
dm.dm_ext_aia_sales
group by
ym,
inst_code
having
sum(value) <> 0
)
,sales_2 as (
select
t1.inst_code,
t1.ym,
t2.max_ym,
t2.ym_12m,
t2.ym_12m_before,
t2.ym_24m,
t2.ym_24m_before
from sales_1 t1
cross join ym_range t2
)
,flag_12m as (
select inst_code,
'滚动一年有数' as aia_provided_flag,
'AIA(Monthly)' as DATA_SOURCE
from sales_2
where ym <= max_ym
and ym >= ym_12m_before
group by inst_code
having count(1) = (select ym_12m from ym_range)
)
,flag_24m as (
select inst_code,
'滚动两年有数' as aia_provided_flag,
'AIA(Monthly)' as DATA_SOURCE
from sales_2
where ym <= max_ym
and ym >= ym_24m_before
group by inst_code
having count(1) = (select ym_24m from ym_range)
)
select inst_code,
aia_provided_flag,
DATA_SOURCE
from flag_12m
union all
select inst_code,
aia_provided_flag,
DATA_SOURCE
from flag_24m
union all
select '' as inst_code,'' as aia_provided_flag,'IQVIA-CHPA(Monthly)' as data_source
union all
select '' as inst_code,'' as aia_provided_flag,'XH Data(Quarterly)' as data_source
union all
select '' as inst_code,'' as aia_provided_flag,'EC(Monthly)' as data_source
union all
select '' as inst_code,'' as aia_provided_flag,'Retail(Quarterly)' as data_source
union all
select '' as inst_code,'' as aia_provided_flag,'CHC(Quarterly)' as data_source
union all
select '' as inst_code,'' as aia_provided_flag,'THC(Quarterly)' as data_source
union all
select '' as inst_code,'' as aia_provided_flag,'IQVIA-COUNTY(Quarterly)' as data_source