Home > Database > Mysql Tutorial > body text

对SQLServer中有主键的表tb,写出效率较高的翻到第二页的sql查询

WBOY
Release: 2016-06-07 15:39:45
Original
1587 people have browsed it

declare @pageSize int --返回一夜的记录数 declare @CurPage int --页号(第几页) declare @Count int declare @id int set @pageSize=10 set @CurPage =1 --定位 if @CurPage = -1 begin --最后一页 set rowcount @pageSize select @id=newsID from newsT

declare @pageSize int      --返回一夜的记录数

declare @CurPage int   --页号(第几页)

declare @Count int

declare @id int

set @pageSize=10
set @CurPage =1

--定位
if @CurPage = -1
begin
 --最后一页
 set rowcount @pageSize
 select @id=newsID from newsTemp   order by newsID
end

if @CurPage > 0
begin
 set @Count = @pageSize * (@CurPage -1) + 1
 set rowcount @Count
 select @id=newsID from newsTemp   order by newsID desc
end

--返回记录
set rowcount @pageSize
select * from newsTemp where newsID

set rowcount 0

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template