msql
=================================
select count(*)/10 from hy_jbxx
select top 10 *
from hy_jbxx
where (hybh not in
(select top 30 hybh
from hy_jbxx
order by hybh))
order by hybh
select top 页大小 *
from testtable
where (id not in
(select top 页大小*页数 id
from 表
order by id))
order by id
==================================
mssql
create procedure pr_getarticles —-这里为存储过程名称
@page int ,
@pagenum int
as
declare @tablename nvarchar(20)
set @tablename='article' —–表名
declare @idname nvarchar(20)
set @idname='article_id' —–表id名
declare @strsql nvarchar(4000)
declare @topnum int
set @topnum=(@page-1)*@pagenum
set @strsql=n'select top'+ str(@pagenum)+' *
from '+@tablename+'
where '+@idname+'>
(
select isnull(max('+@idname+'),0)
from
(
select top '+str( @topnum)+' '+@idname+' from '+@tablename+' order by '+@idname+'
) a
)
order by '+@idname+"
print (@strsql)
exec(@strsql)
go
mssql
分页方案三:(利用id大于多少和select top分页)
语句形式:
select top 10 *
from testtable
where (id >
(select max(id)
from (select top 20 id
from testtable
order by id) as t))
order by id
select top 页大小 *
from testtable
where (id >
(select max(id)
from (select top 页大小*页数 id
from 表
order by id) as t))
order by id
创建分页数据表,同时保存2万条记录
create table [testtable] (
[id] [int] identity (1, 1) not null ,
[firstname] [nvarchar] (100) collate chinese_prc_ci_as null ,
[lastname] [nvarchar] (100) collate chinese_prc_ci_as null ,
[country] [nvarchar] (50) collate chinese_prc_ci_as null ,
[note] [nvarchar] (2000) collate chinese_prc_ci_as null
) on [primary]
go
sqlite ,mysql
select * from table limit pagesize offset pageindex*pagesize
----------------------------------------------------------------------------------
本文深入探讨了SQL分页技术在MSSQL中的应用,通过实例展示了如何使用存储过程来实现高效的数据分页操作。重点介绍了利用SQL语句和存储过程结合实现分页的具体方法,包括使用TOP关键字、子查询以及动态生成SQL字符串等技巧。
874

被折叠的 条评论
为什么被折叠?



