-- Databricks notebook source
--NFC 处理成宽表
insert overwrite table dwd.dwd_ims_nfc_hierarchy 
SELECT * 
  FROM (SELECT NewFormClass_ID as NFC1_ID,
               NewFormClass_Code as NFC1_CODE,
               NewFormClass_Name as NFC1_DES
          FROM dwd.dwd_ims_td_new_form_class NFC
         WHERE NewFormClass_Level = '1') NFC1

  LEFT JOIN (SELECT NewFormClass_ID as NFC2_ID,
                    NewFormClass_Code as NFC2_CODE,
                    NewFormClass_Name as NFC2_DES
               FROM dwd.dwd_ims_td_new_form_class NFC
              WHERE NewFormClass_Level = '2') NFC2
    ON NFC1.NFC1_CODE =
  LEFT (NFC2.NFC2_CODE, 1)

  LEFT JOIN (SELECT NewFormClass_ID as NFC3_ID,
                    NewFormClass_Code as NFC3_CODE,
                    NewFormClass_Name as NFC3_DES
               FROM dwd.dwd_ims_td_new_form_class NFC
              WHERE NewFormClass_Level = '3') NFC3
    ON NFC2.NFC2_CODE =
  LEFT (NFC3.NFC3_CODE, 2)
;