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

在线等一个sql语句的优化问题
select   info_information.id,info_title,class_b,mode, 'price '=case   when   price=0   then   '面谈 '   when   price <> 0   then   price+ '元 '   end,city,pubdate,scannums   from   info_information,info_class_b,info_mode   where   info_class_b.id=class_bid   and   info_mode.id=modeid   and   class_bid   in   (select   id   from   info_class_b   where   class_aid=@class_aid   )   and   modeid=@modeid   order   by   istop   desc,pubdate   desc
数据表中有20万条数据,查询性能很差,希望高手们能给出优化的建议,还有怎么样建立索引能提高查询速度?

------解决方案--------------------
select info_information.id,
info_title,
class_b,
mode,
'price '=case when isnull(price,0)=0 then '面谈 ' else price+ '元 ' end,--改为else就可以判断了
city,pubdate,
scannums
from info_information,info_class_b,info_mode
where info_class_b.id=class_bid
and info_mode.id=modeid
--这句去掉,加在下面where中了
-- and class_bid in (select id from info_class_b where class_aid=@class_aid )
and modeid=@modeid
and info_class_b.class_aid=@class_aid
order by istop desc,pubdate desc
------解决方案--------------------
把各字段所属的表标明一下,总的来说感觉用
select ..from
info_class_b as tb1
inner join
info_class_b as tb2
on tb1.class_aid=@class_aid
and tb1.id=tb2.class_bid
..