从Table表中取出第m条到第n条的记录,有办法把两个LIKE归为一个LIKE么
SELECT TOP n-m+1 id FROM Table WHERE (id NOT IN (SELECT TOP m-1 id FROM Table WHERE title LIKE '%关键字%'))  and title LIKE '%关键字%'

解决方案 »

  1.   

    ;with cte as
    (
     select id0=row_number() over(order by id),* from tablename
    )
    select * from cte where id0 between n to m WHERE title LIKE '%关键字%
      

  2.   

    先将由like检索出的记录放到临时表,然后再进行选取,这样可以少扫描一次主表。
      

  3.   

    select top n into #t from tb where title LIKE '%关键字%' order by ..
    select TOP (n-m+1)  from #t order by....