mysql,sql server2005,oracle三种数据库分页sql语句

每页显示数据数:pageSize      页号:pageNo

Mysql分页:

SELECT * FROM TABLE_NAME LIMIT 0, 10      

表示从第11条数据开始取20条数据返回,limit后的2个参数含义为:起点和步长,即从那条数据开始,取多少条数据.

select * from table_name limit (pageNo-1)*pageSize,pageSize

 

Sql server 2005 分页:

SELECT * FROM  
    ( SELECT ROW_NUMBER() OVER (ORDER BY id desc)  AS  Row,*  from news )  as temp  
where temp.Row between (pageNo-1)*pageSize and pageSize 

 

oracle分页:

 可分为以下三步:
     按id降序排序:
          select * from table_name order by id desc;
       为第一步的数据加上rownum: 
               select rownum as r ,* from (select * from  table_name order by id desc);
       取出第6—10条记录:
          select * from(   
                   select rownum as r ,* from
                       (select * from  table_name order by id desc))
                            where r>=6 and r<=10;

 

你可能感兴趣的:(SQL Server)