try:
-------------------------------------------------------------------------------
SELECT  count(*)
    FROM group grp,
         (SELECT *
            FROM custom_hist a
           WHERE exists (
                    SELECT 1
                        FROM custom_hist c
                       WHERE c.start_num <= '20050131' || '235959999'
                         AND c.end_num >= '20050131' || '235959000'
                         AND c.stop_stat<> '4'
                         AND a.person_cd = c.person_cd
                         AND a.danmn_start_num = c.danmn_start_num)) custom,
         (SELECT *
            FROM custom_Address_hist a
           WHERE exists(
                    SELECT  1
                        FROM custom_Address_hist c
                       WHERE c.start_num <= '20050131' || '235959999'
                         AND c.end_num >= '20050131' || '235959000'
                         AND c.adrClassify = '1'
                         AND a.person_cd = c.person_cd
                         AND a.addr_set_classfiy = c.addr_set_classfiy
                         AND a.danmn_start_num = c.danmn_start_num)) customAddr
   WHERE grp.grpCd = custom.grpCd
     AND grp.start_ymd <= '20050131'
     AND grp.end_ymd >= '20050131'
     AND custom.person_cd = customAddr.person_cd(+)
     AND customAddr.adrClassify(+) = '1'
     AND custom.stop_stat<> '4'

解决方案 »

  1.   

    alter autotrace traceonly;
    看看执行计划
      

  2.   

    用PL/Sql Dev ,点F5察看PLAN表,具体是如何扫描表结构的
      

  3.   

    你是sql有问题,将它分成两条吧!
     如 select * from ...
         where id=(select max(id) from .. where .... )
    最多可能只需10秒.
      

  4.   

    修改了一下,你试试看效果:select count (*)
      from xgroup grp
         , (select *
              from custom_hist a
             where start_num <= '20050131' || '235959999'
               and end_num >= '20050131' || '235959000'
               and stop_stat <> 4
               and custom.danmn_start_num in (
                      select max (danmn_start_num)
                        from custom_hist
                       where person_cd = a.person_cd
                         and start_num <= '20050131' || '235959999'
                         and end_num >= '20050131' || '235959000'
                         and stop_stat <> 4)) custom
         , (select *
              from custom_address_hist a
             where start_num <= '20050131' || '235959999'
               and end_num >= '20050131' || '235959000'
               and adrclassify = '1'
               and danmn_start_num in (
                      select max (damnm_start_num)
                        from custom_address_hist
                       where person_cd = a.person_cd
                         and addr_set_classfiy = a.addr_set_classfiy
                         and start_num <= '20050131' || '235959999'
                         and end_num >= '20050131' || '235959000'
                         and adrclassify = '1')) customaddr
     where grp.grpcd = custom.grpcd
       and grp.start_ymd <= '20050131'
       and grp.end_ymd >= '20050131'
       and custom.person_cd = customaddr.person_cd(+)
       and customaddr.adrclassify(+) = '1';
      

  5.   

    max  .... in  可一想一下用分析函数
      

  6.   

    非常感谢各位的帮忙,已经搞定。KingSunSha(弱水三千) 提供的方法。不过,后来测试了一下,具体哪种性能好,还是和ORACLE的优化模式有关系。