当前位置:首页 > 建站常识 > 列表

sql利用ID大于多少和SELECT TOP分页

点击:时间:2017/8/13关键词:上海网页设计 上海网站建设安全 asp程序
sql分页:利用ID大于多少和SELECT TOP分页程序代码部分:SELECT TOP 页大小 * FROM TestTable WHERE (ID > (SELECT MAX(id) FROM (SELECT TOP 页大小*页数 id FROM
sql利用ID大于多少和SELECT TOP分页
sql分页:利用ID大于多少和SELECT TOP分页
 程序代码部分:

SELECT TOP 页大小 *  

FROM TestTable  

WHERE (ID > (SELECT MAX(id) FROM (SELECT TOP 页大小*页数 id FROM 表 ORDER BY id) AS T))  

ORDER BY ID

ASP超高效分页算法<%'每页的记录数dim pagesizepagesize= "30" '读出总记录数,总页数Dim TotalRecords,TotalPagesSQLstr="Select count(id) As RecordSum From table1"Set Rs=conn.Execute(SQLstr,0,1) TotalRecords=Rs("RecordSum") if Int(TotalRecords/pagesize)=TotalRecords/pagesize thenTotalPages=TotalRecords/pagesizeelseTotalPages=Int(TotalRecords/pagesize)+1end ifRs.Close Set Rs=Nothing '当前页码dim pagepage=Request("page")if isnumeric(page)=false thenresponse.write "<SCRIPT language=JavaScript>alert('参数错误!');"response.write "window.close();</SCRIPT>"response.endend ifIf page="" or page<1 Then page=1If page-TotalPages>0 Then page=TotalPagespage=int(page)if page=1 thensql="select top "&pagesize&" id,title,time from table1 order by time desc"elsesql="select top "&pagesize&" id,title,time from table1 where time<(SELECT Min(time) FROM (SELECT TOP "&pagesize*(page-1)&" time FROM table1 ORDER BY time desc) AS T) order by time desc"end ifSet rs = Server.CreateObject ("ADODB.Recordset")rs.Open sql,conn,1,1Do While Not rs.Eofresponse.write "每条记录信息:"&rs("id")&"<br>"rs.movenextlooprs.closeset rs=nothing''翻页代码省略……%> 

预约建站
免费提供网站优化
领取关键词