将这段
select swjg_dm,cxrq,nsrbh,zsxm_dm,fdbz from zfkh_gl_fdqmqk where 
(nsrbh,zsxm_dm) not in (select nsrbh,zsxm_dm from zfkh_gl_fdqmqk where to_char(cxrq,'yyyy-mm')='2005-02')
改为:
select swjg_dm,cxrq,nsrbh,zsxm_dm,fdbz from zfkh_gl_fdqmqk a where not exists
(select nsrbh,zsxm_dm from zfkh_gl_fdqmqk b where a.nsrbh = b.nsrbh and a.zsxm_dm = b.zsxm_dm and to_char(cxrq,'yyyy-mm')='2005-02')

解决方案 »

  1.   

    union 换成 union all 会快很多
      

  2.   

    用max()over() 函数处理
     create table test (month number(2),charge number(4));
               
               insert into test values (1,100);
               insert into test values (2,107);
               insert into test values (1,101);
               insert into test values (3,100);
               insert into test values (1,103);
               insert into test values (3,110);
               commit;
    SQL> select * from test order by charge;MONTH CHARGE
    ----- ------
        1    100
        3    100
        1    101
        1    103
        2    107
        3    1106 行 已选择已执行耗时0.047 秒SQL> select max(month)over(partition by charge order by charge) month,charge from test;     MONTH CHARGE
    ---------- ------
             3    100
             3    100
             1    101
             1    103
             2    107
             3    1106 行 已选择已执行耗时0.047 秒要去重就你自己处理吧^_^