我正在尝试将客户分为三组REMIC,REMIR和HC
号码为' 682010',' 682020'' 683220'是HC - >其他是REMIC或REMIR REMIR =在商业房地产中没有违约风险(04),但在住宅中有违约风险(05)
我已经创建了一个案例公式,但是它一直给我错误3625 - 我知道我应该计算正确,所以看不到错误
select
CU.CD03001 as "Local Customer ID",
case
when "Commercial Real Estate EAD" is null then 'O'
else 'X'
end as "Commercial Status",
case
when "Residential Real Estate EAD" is null then 'O'
else 'X'
end as "Residential Status",
case
when CU.CD03008='DK'
and CU.CD03025 not in ('682010','682020','683220')
and "Commercial Status" = 'O'
and "Residential Status" = 'X'
then 'REMIR'
when CU.CD03008='DK'
and CU.CD03025 in ('682010','682020','683220')
then 'HC'
else 'REMIC'
end as "Customer Group",
CU.CD03010 as Business_Partner_Name,
ORG1.CD01007_Cd as BA1,
ORG1.CD01008 as BA2,
BA2_NM.Acctng_unit_com_nm AS "Banking Unit",
case ORG1.CD01008
when '6002092' then ORG1.region_cd
else ORG1.CD01009
end as BA3,
BA3_NM.Acctng_unit_com_nm AS "Branch Region",
SD.Common_Cust_Seg_Lvl3_CD,
SD.Common_Cust_Seg_Lvl3_Desc,
CU.CD09075 as Rating,
COALESCE(sum(Case when CR.CD09076_Collateral_Category_Cd = '04' then CR.CD09014_Exposure_at_Default else 0 END),0) as "Commercial Real Estate EAD",
COALESCE(sum(Case when CR.CD09076_Collateral_Category_Cd = '05' then CR.CD09014_Exposure_at_Default else 0 END),0) as "Residential Real Estate EAD"
FROM PROD_INT_SL_DX_VIEWS.organization_dim ORG1
LEFT JOIN ( SELECT
Customer_Id,
CD03001,
CD03008,
CD03010,
CD03025,
CD03026,
CD03029,
CD09075
FROM PROD_INT_SL_DX_VIEWS.customer_dim
where CD03025='L'
and CD03008 = 'DK'
group by 1,2,3,4,5,6,7,8 ) CU
ON ORG1.CD01001=CU.CD03026
LEFT JOIN
(SELECT DISTINCT CD01001, Acctng_unit_com_nm
FROM PROD_INT_SL_DX_VIEWS.ORGANIZATION_HIER) AS BA2_NM
ON TRIM(ORG1.CD01008) = TRIM(BA2_NM.CD01001)
LEFT JOIN
(SELECT DISTINCT CD01001, Acctng_unit_com_nm
FROM PROD_INT_SL_DX_VIEWS.ORGANIZATION_HIER) AS BA3_NM
ON TRIM(BA3) = TRIM(BA3_NM.CD01001)
LEFT JOIN PROD_INT_SL_DX_VIEWS.customer_segment_dim SD
ON CU.CD03029=SD.CD03029
LEFT JOIN PROD_INT_SL_CPS_VIEWS.Financial_Fact FF
on CU.Customer_Id=FF.Customer_Id
LEFT JOIN PROD_INT_SL_CPS_VIEWS.PRODUCT_DIM PD
ON FF.Product_Party_Type_Id=PD.Product_Party_Type_Id
LEFT JOIN PROD_INT_SL_CPS_VIEWS.CREDIT_RISK_FACT CR
ON FF.Agreement_Id=CR.Agreement_Id
where BA1='6002000'
and BA2 in ('6002091')
and SD.Common_Cust_Seg_Lvl3_CD in ('C30100','C20100','C10100','RB_C50100','C60100')
and FF.Year_Month_Id in ('201409') and FF.period_type in ('AVGP','AVGY')
and FF.CD12001_Currency_Unit='EUR'
and PD.Language_Code='eng'
group by 1,2,3,4,5,6,7,8,9,10,11,12,13
order by 1