PS:优化 SQL 语句我估计不太可行,语句是需求那边直接给的。如果要优化也是需求那边的问题。我的主要疑问是: #补充 SQL 语句如下: select d.cplyno, NVL(SUM(NVL(d.n_sum, 0)), 0) from (SELECT NVL(N_GET_PRM, 0) n_sum, a.c_ply_no cplyno FROM T_FIN_PLYEDR_COLDUE@linkzysyscard.regress.rdbms.dev.us.oracle.com A, t_ply_base@linkzysyscard.regress.rdbms.dev.us.oracle.com b WHERE a.c_cha_cde in ('55001247','55020299000760') and a.c_edr_no is null and a.c_ply_no = b.c_ply_no and b.cardno='0650mt' /* and a.c_prod_no like '0650mt'|| '%'*/ and exists (SELECT C_DPT_CDE FROM t_department WHERE c_dpt_cde = a.c_dpt_cde and c_company_cde in (SELECT c_company_cde FROM t_department WHERE C_DPTACC_CDE = '55')) and b.t_udr_date BETWEEN to_date('2017-11-30 00:00:00', 'YYYY-MM-DD HH24:MI:SS') AND to_date('2017-12-31 23:59:59', 'YYYY-MM-DD HH24:MI:SS') and b.c_b2b_udr_mrk <> 'X' and N_GOT_PRM = 0 and T_CHARGE_TM is null union all SELECT NVL(N_GET_PRM, 0) n_sum, a.c_edr_no cplyno FROM T_FIN_PLYEDR_COLDUE@linkzysyscard.regress.rdbms.dev.us.oracle.com A, t_edr_base@linkzysyscard.regress.rdbms.dev.us.oracle.com b, t_ply_base@linkzysyscard.regress.rdbms.dev.us.oracle.com c WHERE a.c_cha_cde in ('55001247','55020299000760') and a.c_edr_no is not null and a.c_edr_no = b.c_edr_no and b.c_ply_no=c.c_ply_no /* and a.c_prod_no like '0650mt' || '%'*/ and exists (SELECT C_DPT_CDE FROM t_department WHERE c_dpt_cde = a.c_dpt_cde and c_company_cde in (SELECT c_company_cde FROM t_department WHERE C_DPTACC_CDE = '55')) and b.t_udr_date BETWEEN to_date('2017-11-30 00:00:00', 'YYYY-MM-DD HH24:MI:SS') AND to_date('2017-12-31 23:59:59', 'YYYY-MM-DD HH24:MI:SS') and b.c_b2b_udr_mrk <> 'X' and N_GOT_PRM = 0 and c.cardno='0650mt' and T_CHARGE_TM is null) d group by d.cplyno order by d.cplyno;