语名如下:
select top 300 * from kq_source where tt>='1'  and tt<='100'  
and  empid in (select id from zlemployee where Dept='zx'  and state<>'9')
执行速度在1分钟左右~如IN后面直接用值却很快。
请高手帮我优化!

解决方案 »

  1.   

    select 
        top 300 t.* 
    from 
        kq_source t
    where 
        t.tt>='1' and t.tt<='100'  
        and 
        exists(select 1 from zlemployee where Dept='zx' and state<>'9' and id=t.empid)
      

  2.   

    libin_ftsafe 我试了一下速度还是差不多~补充一点
    kq_source 表中大约有100万条记录
    zlemployee  表中大约2000条记录麻烦再帮我看看
      

  3.   

    主要是表zlemployee查找速度耗时,Dept,state建立索引,或者把那个大表分成几个小的放到几个服务器上进行联合查询或许能快些。
    select id from zlemployee where Dept='zx'  and state<>'9'
      

  4.   

    select top 300 * from kq_source ,
    ((select id from zlemployee where Dept='zx'  and state<>'9')) t
    where tt>='1'  and tt<='100'  and kq_source.empid = t.id
      

  5.   

    能对TT列进行排序吗?select top 300 * from kq_source ,
    ((select id from zlemployee where Dept='zx' and state<>'9')) t
    where tt>='1' and tt<='100' and kq_source.empid = t.id