create view vi_lb_identity_check as (
SELECT A.NAME AS FULLNAME, A.CERTID AS CERTID, A.RELATION AS RELATION, A.FLOWUNID AS FLOWUNID, A.PHONE AS PHONE
FROM (
    SELECT UT.NAME           AS NAME,
           UT.CERTID         AS CERTID,
           (CASE
                WHEN (UT.PARTNER_ = 'Y') THEN '共同申请人'
                WHEN ((UT.PARTNER_ = 'N') AND (UT.SPOUSE_ = 'Y')) THEN '配偶'
                WHEN (UT.PARTNER_ = 'gua') THEN '担保人'
                WHEN (UT.PARTNER_ = 'cust') THEN '申请人'
                ELSE '' END) AS RELATION,
           UT.FLOWUNID       AS FLOWUNID,
           UT.PHONE          AS PHONE
    FROM (
        SELECT CF1.NAME AS NAME, CF1.CERTID AS CERTID, CF1.PARTNER_ AS PARTNER_, CF1.SPOUSE_ AS SPOUSE_, CF1.FLOWUNID AS FLOWUNID, CF1.TEL AS PHONE
        FROM APZL.CUSTOMER_FAMILY_TEMP CF1
        WHERE (CF1.PARTNER_ = 'Y')
        UNION ALL
        (
            SELECT LGUT.FULLNAME AS FULLNAME,
                   LGUT.CERTID   AS CERTID,
                   'gua'         AS PARTNER_,
                   'gua'         AS SPOUSE_,
                   LGUT.FLOWUNID AS FLOWUNID,
                   LGUT.MOBILE   AS PHONE
            FROM APZL.LB_GUARANTEE_UNIT_TEMP LGUT
        )
        UNION ALL
        (
            SELECT CCPT.FULLNAME AS FULLNAME,
                   CCPT.CERTID   AS CERTID,
                   'cust'        AS PARTNER_,
                   'cust'        AS SPOUSE_,
                   CCPT.FLOWUNID AS FLOWUNID,
                   CCPT.MOBILE   AS PHONE
            FROM APZL.CUSTOMER_PERSON_TEMP CCPT
            WHERE (CCPT.BALANCESHEET = '申请人')
        )
    ) UT
) A);

