select 
    count(*) 
from 
    TGraduateJob a,
    TGraduateBaseInfo b,
    TCollege d,
    TCollege h, 
    TCode g
where 
        a.memberID = b.memberID and a.jobType in (0,2,7,1) 
    and (h.collegeID <> b.collegeID or h.ProvinceID != 7224)
    and g.CodeID=b.WhereFrom 
    and g.CodeTypeID=13 
    and g.CodeValu like '35%'
--以上未经测试.

解决方案 »

  1.   

    楼主,你的sql没写错吧,TCollege d表怎么不和其它表关联,这恐怕是执行n久的主要原因
      

  2.   

    已经出现笛卡儿积了,100万 × 100万(或小于100万) = 用多长时间啊建议不要用Exists,用子查询select a.* from a,(select * from t) b where a.id=b.id 这样的方式
      

  3.   

    你的TCollege d表怎么就没关联呢?这样sql都不正确.性能就不谈了.
      

  4.   

    select count(*) 
      from TGraduateJob a,
           TGraduateBaseInfo b,
           TCollege d
     where a.memberID = b.memberID 
       and a.memberID = d.memberID
       and b.memberID = d.memberID
       and a.jobType in (0,2,7,1) 
       and not exists 
               (
                  select 'X' 
                    from TCollege h  
                   where h.collegeID = b.collegeID  
                     and h.ProvinceID = 7224
               )
       and exists 
           (
             select 'X' 
               from TCode g 
              where g.CodeID=b.WhereFrom 
                and g.CodeTypeID=13 
                and g.CodeValu like '35%'
           )
      

  5.   

    用pro*c程序实现:
    1、禁止关联查询,各自读入内存,且采用批量读出数据的方法,如:for MaxNum (祥见proc编程)
    2、在内存中匹配关联条件
    3、使用一些数据结构中的好的算法,如:平衡二叉树、折半查找、外部排序等。