decode和case when then 当条件使用的案例

SELECT DISTINCT A.C_PORT_CODE,
A.C_IE_CODE,
A.D_TRADE,
decode(a.c_ie_code,'QTFY',decode(trim(a.N_MONEY_REC),0,decode(trim(a.N_MONEY_ACC),0,decode( trim(a.n_MONEY_COP),0,decode(trim(a.n_MONEY_PAY),0,0,1),1),1),1),1) ssss,
A.C_DC_CODE,
A.N_MONEY_REC,
A.N_MONEY_ACC,
A.D_TRADE_YSS,
A.D_TRADE_YSE,
A.N_MONEY_COP,
A.N_MONEY_PAY,
A.D_TRADE_YFS,
A.D_TRADE_YFE,
A.C_CA_CODE,
B.C_DAI_CODE_REC,
B.C_DAI_CODE_COP,
NVL(D.C_FEE_CODE, trim(a.c_fee_code)) AS C_FEE_CODE,
A.C_TD_CHAN_CODE,
C.C_DV_ACC_TYPE,
A.C_YWBH,
A.C_REMARK,
NVL(SEC.C_SEC_CODE, ' ') AS C_SEC_CODE,
CASE
WHEN SEC.C_SEC_CODE IS NOT NULL THEN
SEC.C_SEC_VAR_CODE
ELSE
' '
END AS C_SEC_VAR_CODE,
CASE
WHEN SEC.C_SEC_CODE IS NOT NULL THEN
SEC.C_MKT_CODE
ELSE
' '
END AS C_MKT_CODE,
CASE
WHEN SEC.C_SEC_CODE IS NOT NULL THEN
'PT'
ELSE
' '
END AS C_DTA_CODE,
CASE
WHEN SEC.C_SEC_CODE IS NOT NULL THEN
'SS'
ELSE
' '
END AS C_DV_ISSUE_MODE,
CASE
WHEN SEC.C_SEC_CODE IS NOT NULL THEN
'IC_TD'
ELSE
' '
END AS C_DV_INVEST_CLS
FROM T_D_OD_SZJZ_DATA A
LEFT JOIN T_S_IE_ITEM B
ON trim(A.C_IE_CODE) = B.C_IE_CODE
LEFT JOIN T_P_BI_CASH_ACC C
ON TRIM(A.C_CA_CODE) = C.C_CA_CODE
LEFT JOIN T_P_BI_IE D
on (trim(a.c_fee_code) || '_' || trim(a.C_YWBH) = D.c_fee_code)
or (trim(a.C_YWBH) is null and trim(a.c_fee_code) = D.c_fee_code)
LEFT JOIN T_P_SV_SEC_BASE SEC
ON A.C_SEC_CODE = SEC.C_SEC_CODE
WHERE trim(A.C_PORT_CODE) IN ('000327')
AND A.D_TRADE >= date'2016-12-28'
and A.D_TRADE <= date'2016-12-28'
and trim(A.C_IE_CODE) not in ('CPXS_ZJTQ', 'CPXS_ZJZJ', 'SZJZ_QTSZ')

and
case --case when实现
when a.c_ie_code='QTFY' and trim(a.N_MONEY_REC)=0 and trim(a.N_MONEY_ACC)=0 AND trim(a.n_MONEY_COP)=0 AND trim(a.n_MONEY_PAY)=0
then 0
else 1
end=1
/*decode同样可以实现*/
decode(a.c_ie_code,'QTFY',decode(trim(a.N_MONEY_REC),0,decode(trim(a.N_MONEY_ACC),0,decode( trim(a.n_MONEY_COP),0,decode(trim(a.n_MONEY_PAY),0,0,1),1),1),1),1)=1

场景: 当为and ( a.c_ie_code='QTFY' and trim(a.N_MONEY_REC)=0 and trim(a.N_MONEY_ACC)=0 AND trim(a.n_MONEY_COP)=0 AND trim(a.n_MONEY_PAY)=0 )时数据不查询

posted @ 2017-02-23 15:24  学无止境,前进  阅读(1250)  评论(0编辑  收藏  举报