sql语句执行非常慢....要怎么优化啊?????????????
select top 30 jobs.id,jobs,jobs.degree,tjsj,jobs.zt,jobs.sex, sh.dbo.corporation.id,sh.dbo.corporation.qymc from rencai.dbo.jobs , sh.dbo.corporation where (len(selectedjob)> 1 and len(jobs)> 1 and zt <> 1) and sh.dbo.corporation.id=rencai.dbo.jobs.comid and jobs.id not in(select top 1200 jobs.id from rencai.dbo.jobs where (len(selectedjob)> 1 and len(jobs)> 1 and zt <> 1) and sh.dbo.corporation.id=jobs.comid order by tjsj desc) order by tjsj desc
................................
sql语句执行非常慢,甚至执行不过去,CPU占100%,...要怎么优化啊?
------解决方案--------------------1.建立索引
2.not in 用not exists或(外连接+判断不空)代替
------解决方案--------------------你先把这句“select top 1200 jobs.id from rencai.dbo.jobs where (len(selectedjob)> 1 and len(jobs)> 1 and zt <> 1”的结果集用临时表存放
再把not in 代换为not exists 试试
------解决方案--------------------学习~
------解决方案--------------------看出来了 跨库查询 建议楼主一步一步查询 仅供参考
------------------------
http://fenglin.xland.cn
------------------------