日期:2014-05-17 浏览次数:20610 次
select top 4 * from userinfo where userid not in (select top 4 userid from userinfo order by userid desc)order by userid desc
--用一句SQL取出第 m 条到第 n 条记录的方法
1 --从Table 表中取出第 m 条到第 n 条的记录:(Not In 版本)
select * from Item
select top n-m+1 * from TABLE where (id NOT IN (select top m-1 id FROM TABLE ))
2--从TABLE表中取出第m到n条记录 (Exists版本)
SELECT TOP n-m+1 * FROM TABLE AS a WHERE Not Exists
(Select * From (Select Top m-1 * From TABLE order by id) b Where b.id=a.id )
Order by id
3--m为上标,n为下标,例如取出第8到12条记录,m=8,n=12,Table为表名
这是最好用的一条!
Select Top n-m+1 * From Table Where Id>(Select Max(Id) From
(Select Top m-1 Id From Table Order By Id Asc) Temp) Order By Id Asc
declare @pagesize int ,@pagenum int
set @pagesize= 4--输入
set @pagenum= 2--输入
select *
from userinfo
where id>@pagesize*(@pagenum-1)
and id<=@pagesize*@pagenum
select top 4 *?
from userinfo
where userid
in (select top 8 userid from userinfo order by userid desc)order by userid ASC