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

这个SQL语句查询该如何优化呢?(大家过来实践操作撒!)
以下SQL语句该如何优化,这个SQL语句现在是挺浪费时间的!大家修改后,并给出为什么要这么修好啊!让大家能从理论上学习下!谢谢!

select   Info_Content_Pic.ID,   Info_Content_Pic.InfoID,   Info_Content_Pic.Pic_Big,   Info_Content.Designer   from   Info_Content,   Info_Content_Pic   WHERE   Info_Content_Pic.InfoID=Info_Content.ID   AND     Info_Content_Pic.sClass   like   '%w_yur% '   AND   Info_Content.CategoryID= '16 '     and   Info_Content.Sex= '2 '   Order   by   Info_Content_Pic.UpDateTime   DESC   limit   105,35;


------解决方案--------------------
没看出来什么地方还可以优化.

或许把limit 105,35 换成 top 10535放在前面?
------解决方案--------------------
select
Info_Content_Pic.ID,
Info_Content_Pic.InfoID,
Info_Content_Pic.Pic_Big,
Info_Content.Designer
from Info_Content join Info_Content_Pic --写成标准写法吧

on Info_Content_Pic.InfoID=Info_Content.ID

WHERE

Info_Content.CategoryID= '16 ' and
Info_Content.Sex= '2 ' and
Info_Content_Pic.sClass like '%w_yur% '

/*把LIKE放在最后,不过高手说SQL会自动优化。个人还是有点不放心的感觉,写在后面踏实*/

Order by Info_Content_Pic.UpDateTime DESC

------解决方案--------------------
哦,MYSQL不清楚,MSSQL中join=inner join
------解决方案--------------------
select * from (

select
Info_Content_Pic.ID,
Info_Content_Pic.InfoID,
Info_Content_Pic.Pic_Big,
Info_Content_Pic.sClass,
Info_Content_Pic.UpDateTime,
Info_Content.Designer
from Info_Content join Info_Content_Pic

on Info_Content_Pic.InfoID=Info_Content.ID

WHERE

Info_Content.CategoryID= '16 ' and
Info_Content.Sex= '2 '
) a

where
sClass like '%w_yur% '

Order by UpDateTime DESC limit 105,35;

试试看