復(fù)制代碼 代碼如下:
一頁3條數(shù)據(jù) 取第一頁的數(shù)據(jù)
-- 第一頁
select top 3 * from T_news;
取第五頁的數(shù)據(jù)
--第五頁
select top 3 * from T_News where id not in (select top (3*4) id from T_News) --關(guān)鍵就在于not in上 靠他來去掉前幾頁的數(shù)據(jù)
如果想要自己設(shè)定每頁幾條數(shù)據(jù)和看第幾頁的話也行 就多加個(gè)存儲(chǔ)過程
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
復(fù)制代碼 代碼如下:
一頁3條數(shù)據(jù) 取第一頁的數(shù)據(jù)
select * from (select *,ROW_NUMBER()over(order by id asc) as number from T_News ) as tb1
where number between 1 and 3;
第五頁的數(shù)據(jù)
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;
自己設(shè)定每頁幾條數(shù)據(jù)和看第幾頁
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
新聞熱點(diǎn)
疑難解答
圖片精選