加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

mssql 支持的分页+sqlite + mysql 的分页语句

发布时间:2020-12-12 20:27:59 所属栏目:百科 来源:网络整理
导读: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 (sele

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 limitpagesize offset pageindex*pagesize

----------------------------------------------------------------------------------

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读