| 到 第1010条的数据 这样就造成了 查询出的记录数很少,但网络传输数据量很大!
因此比较好的分页做法应该是: 每次翻页的时候只从数据库里检索页面大小的块区的数据。这样虽然每次翻页都需要查询数据库,但查询出的记录数很少,网络传输数据量不大,如果使用连接池更可以略过最耗时的建立数据库连接过程。而在数据库端有各种成熟的优化技术用于提高查询速度,比在应用服务器层做缓存有效多了。
对于SqlServer 数据库 如要到得第1000-1010条记录:
Select top 10 * from ( Select top 10 * from ( Select top 1010 * from docdetail order by lastmodidate asc ,Id asc ) temptbl1 order by lastmodidate desc ,Id desc ) temptbl2 order by lastmodidate asc,Id asc
对于oracle 数据库 如要到得第1000-1010条记录 由于oracle中的rownum是在查询之后排序之前赋值的.所以其相应的写法应为:
select * from ( select my_table.*, rownum as temptbl_rownum from ( Select * from docdetail order by lastmodidate asc,Id asc ) temptbl where rownum <1010
上一页 [1] [2] [3] [4] 下一页 |