欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

不同数据库'查询第几行到第几行记录'脚本的区别

程序员文章站 2022-05-01 21:03:00
mysql数据库: ① SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset; ② SELECT * FROM table ORDER BY id LIMIT [offset,] rows | rows OFFSET offset ......

mysql数据库:

  ① select * from table limit [offset,] rows | rows offset offset;

  ② select * from table order by id limit [offset,] rows | rows offset offset;

pgsql数据库:

  ① select * from table limit 10 offset 20;

  ② select * from table order by id limit 10 offset 20;

mssql数据库:

  ① select top 10 * from table where id in (select top 20 id from table order by id) order by id desc;

  ② select identity(int,1,1) id,* into temp from table;select * from temp id between 10 and 20;

oracle数据库:

  ① select * from table where rownum < 20 

    minus 

    select * from table where rownum < 10;

  ② select * from (select t.*, row_number() over(order by id)rowid from table t) where rowid between 10 and 20;