日期:2014-05-17  浏览次数:20528 次

求优化这个SQL运行时间,现在是17秒
select * from 基本信息表1 left join (select * from 基本沟通表1 where Gid IN (select Max(Gid) from 基本沟通表1 group by 基本沟通表1.Qid)) as t2 on 基本信息表1.id =t2.Qid where 1=1
and t2.求职状态='情况不明'

------解决方案--------------------
执行计划贴出来
------解决方案--------------------
select * from 基本信息表1 left join
(select t3.* from 基本沟通表1 t3 inner join (select Max(Gid) from 基本沟通表1 group by 基本沟通表1.Qid) t4
on t3.gid=t4.gid and t3.qid=t4.qid) t2
on 基本信息表1.id =t2.Qid 
where 1=1 and t2.求职状态='情况不明' 
------解决方案--------------------
应该用inner join 
试试我这句要多久

select * from 基本信息表1 a inner    基本沟通表1 b 
on a.id=b.qid
and b.求职状态='情况不明'
and not exists (select c.gid from 基本沟通表1 c on c.qid=b.qid and c.Gid>b.Gid)