sql 分页

oracle :oracle分页有通用写法,假设一页5行

select * from (select rownum as r, t.* from(select * from house)t where rownum<=pageIndex*pageSize) where r>(pageIndex-1)*pageSize

其中pageIndex是你要查找的页码,pageSize是你每页多少条记录 

 

如果基础查询不需要排序,可以省掉一层嵌套 select * from ( select t.*,rownum from table1 t where condition ) where rownum>(pangeNow-1)*5 and rownum<=(pageNow)*5

适用于 SQL Server 2000/2005
SELECT TOP 页大小 * FROM table1 WHERE id NOT IN ( SELECT TOP 页大小*(页数-1) id FROM table1 ORDER BY id ) ORDER BY id
方法2:
适用于 SQL Server 2000/2005
SELECT TOP 页大小 * FROM table1 WHERE id > ( SELECT ISNULL(MAX(id),0) FROM ( SELECT TOP 页大小*(页数-1) id FROM table1 ORDER BY id ) A ) ORDER BY id
方法3:
适用于 SQL Server 2005
SELECT TOP 页大小 * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM table1 ) A WHERE RowNumber > 页大小*(页数-1)
说明,页大小:每页的行数;页数:第几页。使用时,请把“页大小”以及“页大小*(页数-1)”替换成数码。

MYSQL
SELECT * FROM TT LIMIT 1,20
SELECT * FROM TT LIMIT 21,30

SELECT * FROM paper WHERE NAME=2 ORDER BY id LIMIT 0,3 

你可能感兴趣的:(sql)