-- 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


