有关JSP分页的SQL语句!!
rs=state.executeQuery("selectlimit"+(pageNo*5-5)+"5*frombean");这里我们拼了一个sql语句,用来从(page...
rs = state.executeQuery("select limit " + (pageNo * 5 - 5) + " 5 * from bean"); 这里我们拼了一个sql语句,用来从(pageNo * 5 - 5)开始查询五个记录,这条sql语句是hsqldb数据库特有的分页语句。不过我使用的是SQL2005,SQL没有limit,怎么改写上面的SQL语句?谢谢!
展开
展开全部
方式一
select top @pageSize * from company where id not in
(select top @pageSize*(@pageIndex-1) id from company)
@pageSize是每页显示条数
company 表的名字
@pageIndex 总页数
方式二ROW_NUMBER()OVER
--ROW_NUMBER() 就是生成一个有顺序的行号,而他生成顺序的标准,就是后面紧跟的OVER(ORDER BY ID)
--还必须添加OVER语句以便告诉SQL Server你希望怎样添加行序号。
select getdate()
select * from company where id in (
--搜索出settable表中所有的编号,也就是company表中的id,这里只不过要得到num(即有顺序的编号)
select id from
--搜索出出表中的所有的id,并且新建一列num用来存取排序的编号,并且把这张表赋值给settable
(select id,row_number() over (order by id) as
num from company)
as settable
--添加搜索条件页索引和页大小
where num between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize)
select getdate()
方式三
SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY id asc) AS rownum,
id
FROM company ) AS D
WHERE rownum BETWEEN (@pageIndex-1)*@pageSize+1 AND @pageIndex*@pageSize
ORDER BY id asc
select top @pageSize * from company where id not in
(select top @pageSize*(@pageIndex-1) id from company)
@pageSize是每页显示条数
company 表的名字
@pageIndex 总页数
方式二ROW_NUMBER()OVER
--ROW_NUMBER() 就是生成一个有顺序的行号,而他生成顺序的标准,就是后面紧跟的OVER(ORDER BY ID)
--还必须添加OVER语句以便告诉SQL Server你希望怎样添加行序号。
select getdate()
select * from company where id in (
--搜索出settable表中所有的编号,也就是company表中的id,这里只不过要得到num(即有顺序的编号)
select id from
--搜索出出表中的所有的id,并且新建一列num用来存取排序的编号,并且把这张表赋值给settable
(select id,row_number() over (order by id) as
num from company)
as settable
--添加搜索条件页索引和页大小
where num between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize)
select getdate()
方式三
SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY id asc) AS rownum,
id
FROM company ) AS D
WHERE rownum BETWEEN (@pageIndex-1)*@pageSize+1 AND @pageIndex*@pageSize
ORDER BY id asc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
oracle的分页:
select uuid,shopid,name,owner,tel,compname from
(Select rownum r,uuid,shopid,name,owner,tel,compname From Tbl_shop) where r>"+startCount+" and r <="+endCount;
startCount:开始记录数
endCount:结束记录数
mysql的分页:
select * from article limit "+startCount+", "+pageSize+";
startCount:开始记录数
pageSize:每页记录数
MSSQL的分页:
select * from ( select TOP pagesize * FROM ( SELECT TOP pagesize*cureentpage * from user_table ORDER BY id ASC ) as aSysTable ORDER BY id DESC ) as bSysTable ORDER BY id ASC
pagesize: 每页显示记录数
cureentpage:当前页数
select uuid,shopid,name,owner,tel,compname from
(Select rownum r,uuid,shopid,name,owner,tel,compname From Tbl_shop) where r>"+startCount+" and r <="+endCount;
startCount:开始记录数
endCount:结束记录数
mysql的分页:
select * from article limit "+startCount+", "+pageSize+";
startCount:开始记录数
pageSize:每页记录数
MSSQL的分页:
select * from ( select TOP pagesize * FROM ( SELECT TOP pagesize*cureentpage * from user_table ORDER BY id ASC ) as aSysTable ORDER BY id DESC ) as bSysTable ORDER BY id ASC
pagesize: 每页显示记录数
cureentpage:当前页数
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询