主流数据库分页的SQL语句
主流数据库对分页查询都有不同程度的支持,下面分别是SQLServer、Oracle、MySQL的分页查询语句(从cpcode表中查询出90-100的10条记录),以备查询。
SQLServer:
- select * from (select top 10 * from (select top 100 * from cpcode order by code) a order by code desc) as b order by code
Oracle:
sql 代码
- select * from (select rownum as rn1,code,name from cpcode where rownum<=100) where rn1 >=91
MySQL:
sql 代码
- select * from cpcode limit 90,10
oracle 另一种方法:
select * from ( select a.*, rownum rn from (select * from tableName) a )
where rn between 10 and 40