您可以使用COALESCE
SELECT
SUM ( DISBURSE_AMT )
FROM
SPEC_GT1
WHERE
COALESCE ( INSTANCE_CODE_1,
INSTANCE_CODE_2,
INSTANCE_CODE_3,
INSTANCE_CODE_4,
INSTANCE_CODE_5 ) = 3;
你可以试试这个示例:
WITH SPEC_GT1
AS (SELECT
1 AS DISBURSE_AMT,
3 AS INSTANCE_CODE_1,
3 AS INSTANCE_CODE_2,
3 AS INSTANCE_CODE_3,
NULL AS INSTANCE_CODE_4,
3 AS INSTANCE_CODE_5
FROM
DUAL
UNION ALL
SELECT
2 AS DISBURSE_AMT,
3 AS INSTANCE_CODE_1,
3 AS INSTANCE_CODE_2,
3 AS INSTANCE_CODE_3,
3 AS INSTANCE_CODE_4,
3 AS INSTANCE_CODE_5
FROM
DUAL
UNION ALL
SELECT
3 AS DISBURSE_AMT,
3 AS INSTANCE_CODE_1,
NULL AS INSTANCE_CODE_2,
3 AS INSTANCE_CODE_3,
3 AS INSTANCE_CODE_4,
3 AS INSTANCE_CODE_5
FROM
DUAL
UNION ALL
SELECT
4 AS DISBURSE_AMT,
3 AS INSTANCE_CODE_1,
3 AS INSTANCE_CODE_2,
2 AS INSTANCE_CODE_3,
3 AS INSTANCE_CODE_4,
3 AS INSTANCE_CODE_5
FROM
DUAL)
SELECT
SUM ( DISBURSE_AMT )
FROM
SPEC_GT1
WHERE
COALESCE ( INSTANCE_CODE_1,
INSTANCE_CODE_2,
INSTANCE_CODE_3,
INSTANCE_CODE_4,
INSTANCE_CODE_5 ) = 3