提几点意见:根据搂主的意思,首先,union是否可以换成union all,这样可以有效提高效率,其次,不要用not in,用not exists或者外联接判断空代替,还有用了not in没必要再有distinct吧

解决方案 »

  1.   

    试试改进下算法:
    select * from (
    SELECT CUS_LAST_NAME, CUS_MIDDLE_NAME,.....,
           row_number() over(partition by cus_license_number,order by cus_address_type desc) rn
    WHERE lower(cus_last_name) like '%smith%' and cus_address_type in ('01','02)
    ) where rn = 1
      

  2.   

    改正下:
    select * from (
    SELECT CUS_LAST_NAME, CUS_MIDDLE_NAME,.....,
           row_number() over(partition by cus_license_number order by cus_address_type desc) rn
    WHERE lower(cus_last_name) like '%smith%' and cus_address_type in ('01','02)
    ) where rn = 1
      

  3.   

    lower(cus_last_name) like '%smith%' 
    应该可以改为cus_last_name like '%SMITH%'
      

  4.   

    cus_last_name like '%SMITH%'
    也用不到索引
    不如用instr,然后建一个函数索引