create view vi_lb_car_credit_investigation as (
SELECT A.NAME AS FULLNAME, A.TEL AS PHONENUMBER, A.CERTID AS CERTID, A.RELATION AS RELATION, A.FLOWUNID AS FLOWUNID
FROM (
    SELECT UT.NAME           AS NAME,
           UT.TEL            AS TEL,
           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
    FROM (
        SELECT CF1.NAME AS NAME, CF1.TEL AS TEL, CF1.CERTID AS CERTID, CF1.PARTNER_ AS PARTNER_, CF1.SPOUSE_ AS SPOUSE_, CF1.FLOWUNID AS FLOWUNID
        FROM APZL.CUSTOMER_FAMILY_TEMP CF1
        UNION ALL
        (
            SELECT LGUT.FULLNAME AS NAME, LGUT.MOBILE AS TEL, LGUT.CERTID AS CERTID, 'gua' AS PARTNER_, 'gua' AS SPOUSE_, LGUT.FLOWUNID AS FLOWUNID
            FROM APZL.LB_GUARANTEE_UNIT_TEMP LGUT
        )
        UNION ALL
        (
            SELECT CCPT.FULLNAME AS NAME, CCPT.MOBILE AS TEL, CCPT.CERTID AS CERTID, 'cust' AS PARTNER_, 'cust' AS SPOUSE_, CCPT.FLOWUNID AS FLOWUNID
            FROM APZL.CUSTOMER_PERSON_TEMP CCPT
            WHERE (CCPT.BALANCESHEET = '申请人')
        )
    ) UT
) A);

