一页3条数据 取第一页的数据 -- 第一页 select top 3 * from T_news; 取第五页的数据 --第五页 select top 3 * from T_News where id not in (select top (3*4) id from T_News) --关键就在于not in上 靠他来去掉前几页的数据 如果想要自己设定每页几条数据和看第几页的话也行 就多加个存储过程 create proc usp_fenye @geshu int,@yeshu int as begin select top (@geshu) * from T_News where id not in (select top (@geshu*(@yeshu-1)) id from T_News) end
一页3条数据 取第一页的数据 select * from (select *,ROW_NUMBER()over(order by id asc) as number from T_News ) as tb1 where number between 1 and 3; 第五页的数据 select * from (select *,ROW_NUMBER()over(order by id asc) as number from T_News ) as tb1 where number between 3*4+1 and 3*5; 自己设定每页几条数据和看第几页 create proc usp_fenye @geshu int,@yeshu int as begin select * from (select *,ROW_NUMBER()over(order by id asc) as number from T_News ) as tb1 where number between @geshu*(@yeshu-1)+1 and @geshu*@yeshu; end