日期:2014-05-18  浏览次数:20597 次

求一语句的优化写法
select   ...   from   logisticsproject,projectbatch   where
logisticsproject.mainkey   =   projectbatch.projectkey   and   logisticsproject.projecttypeid= '值 '   and  
projectbatch.projectbatchid= '值 '   and   ...   and
projectbatch.mainkey   in    
(select   projectbatchkey   from   feedetail   where   ratifyid   = '1 '   And   transaccountid   = '0 ')
 
此处查询速度有点慢,请各位给优化一下提高下查询速度。



------解决方案--------------------
select ... from logisticsproject,projectbatch,feedetail where
logisticsproject.mainkey = projectbatch.projectkey and logisticsproject.projecttypeid= '值 ' and
projectbatch.projectbatchid= '值 ' and ... and
projectbatch.mainkey = feedetail.projectbatchkey
and feedetail.ratifyid = '1 ' And feedetail.transaccountid = '0 '

------解决方案--------------------
用in的话确实会慢一些
------解决方案--------------------
--try


select ...
from logisticsproject, projectbatch
where
logisticsproject.mainkey = projectbatch.projectkey and
logisticsproject.projecttypeid= '值 ' and
projectbatch.projectbatchid= '值 ' and ... and
projectbatch.mainkey in
(select distinct projectbatchkey from feedetail where ratifyid = '1 ' And transaccountid = '0 ')
------解决方案--------------------
select ...
from logisticsproject
inner join projectbatch on logisticsproject.mainkey = projectbatch.projectkey and
logisticsproject.projecttypeid= '值 ' and projectbatch.projectbatchid= '值 ' and ...
inner join feedetail on projectbatchkey = projectbatch.mainkey and ratifyid = '1 ' And transaccountid = '0 '

然后该建index的就建index