select top 8 id,class,title,titlecolor,excerpt,annex from t_ar where check=1 and (class like '001030%' or class like '%;001030%') order by top desc,time desc如何优化?

解决方案 »

  1.   

    本帖最后由 roy_88 于 2010-04-02 17:03:18 编辑
      

  2.   

    select top 8 id,class,title,titlecolor,excerpt,annex from t_ar 
    where check=1 and (left(class,6) = '001030' or class like '%;001030%') 
    order by top desc,time desc
      

  3.   

    select top 8 id,class,title,titlecolor,excerpt,annex 
    from t_ar 
    where [check]=1 
    and (class like '001030%' or class like '%;001030%') 
    order by [top] desc,[time] desc几个关键字帮你框一下,遇到 '%内容%'这样的查询,没什么优化的空间了,因为相关列引用不了索引.
      

  4.   

    top是字段名?select top 8 id,class,title,titlecolor,excerpt,annex from t_ar 
    where check=1 and (left(class,6) = '001030' or class like '%;001030%') 
    order by [top] desc,time desc
      

  5.   

    or 可以用union 试试
    like 可以用charindex试试
      

  6.   

    还是可以加索引的  因为只选前8个 如果加了索引 则走SCAN的时候不需要遍历整个表 只选前8 这样效率高很多当然是在数据量比较大的情况下  如果数据量比较小 加索引就没意义了 相反 扫描索引的时间比遍历整个表还长 这个就得不偿失了
      

  7.   

    此语句并发查询(超过40条)的时候or语句严重影响查询速度,class字段建了索引貌似没什么作用。数据库为sql server 2000
      

  8.   


    请问:第二个Top desc 是什么意思呀?我不太明白。