Files
MarketAnalysis-ETL/CHPA/02 dws_ims_td_atc_cn.sql
2026-04-27 11:04:09 +08:00

33 lines
1.4 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
-- 源表DWD.DWD_GND_IMS_TBLATC,DWD.DWD_IMS_ATC_HIERARCHY
-- 目标表DWS.DWS_IMS_TD_ATC_CN
-- COMMAND ----------
--ATC挂中文名
insert overwrite table dws.dws_ims_td_atc_cn
SELECT DISTINCT
T1.ATC1_CODE AS ATC1_COD,
T1.ATC1_DES,
case when ATC1.ATC1_DES_C is null then T1.ATC1_DES else ATC1.ATC1_DES_C end AS ATC1_DES_C,
T1.ATC2_CODe AS ATC2_COD,
T1.ATC2_DES,
case when ATC2.ATC2_DES_C is null then T1.ATC2_DES else ATC2.ATC2_DES_C end AS ATC2_DES_C,
T1.ATC3_CODe AS ATC3_COD,
T1.ATC3_DES,
case when ATC3.ATC3_DES_C is null then T1.ATC3_DES else ATC3.ATC3_DES_C end AS ATC3_DES_C,
T1.ATC4_CODe AS ATC4_COD,
T1.ATC4_DES,
case when ATC4.ATC4_DES_C is null then T1.ATC4_DES else ATC4.ATC4_DES_C end AS ATC4_DES_C,
from_utc_timestamp(current_timestamp(),'UTC+8'),
from_utc_timestamp(current_timestamp(),'UTC+8')
FROM dwd.dwd_ims_ATC_Hierarchy T1
LEFT JOIN (SELECT DISTINCT ATC4_COD,ATC4_DES_C FROM dwd.dwd_gnd_ims_tblATC) ATC4
ON T1.ATC4_CODE = ATC4.ATC4_COD
LEFT JOIN (SELECT DISTINCT ATC3_COD,ATC3_DES_C FROM dwd.dwd_gnd_ims_tblATC) ATC3
ON T1.ATC3_CODE = ATC3.ATC3_COD
LEFT JOIN (SELECT DISTINCT ATC2_COD,ATC2_DES_C FROM dwd.dwd_gnd_ims_tblATC) ATC2
ON T1.ATC2_CODE = ATC2.ATC2_COD
LEFT JOIN (SELECT DISTINCT ATC1_COD,ATC1_DES_C FROM dwd.dwd_gnd_ims_tblATC) ATC1
ON T1.ATC1_CODE = ATC1.ATC1_COD
;