MySQL中OFFSET和FETCH的详解
程序员文章站
2022-05-20 14:36:08
...
OFFSET & FECTH 关键字与ORDER BY结合使用,实现对查询结果的分页
一、单独使用OFFSET:
示例:查询所有职员的信息,按雇佣日期排序并跳过前285条记录(共290条)
1 USE AdventureWorks2014 2 SELECT [BusinessEntityID],[HireDate],[JobTitle] 3 FROM [HumanResources].[Employee] 4 ORDER BY [BusinessEntityID] 5 OFFSET 285 ROWS
查询结果:
BusinessEntityID HireDate JobTitle 1 286 2013-05-30 Sales Representative 2 287 2012-04-16 European Sales Manager 3 288 2013-05-30 Sales Representative 4 289 2012-05-30 Sales Representative 5 290 2012-05-30 Sales Representative
二、OFFSET和FECTH结合使用:
示例:查询所有职员的信息,按雇佣日期排序并跳过前10条记录再显示之后的5条记录
1 USE AdventureWorks2014 2 SELECT [BusinessEntityID],[HireDate],[JobTitle] 3 FROM [HumanResources].[Employee] 4 ORDER BY [BusinessEntityID] 5 OFFSET 10 ROWS 6 FETCH NEXT 5 ROWS ONLY
查询结果:
BusinessEntityID HireDate JobTitle 1 11 2010-12-05 Senior Tool Designer 2 12 2007-12-11 Tool Designer 3 13 2010-12-23 Tool Designer 4 14 2010-12-30 Senior Design Engineer 5 15 2011-01-18 Design Engineer
以上就是MySQL中OFFSET和FETCH的详解的内容,更多相关内容请关注PHP中文网(www.php.cn)!
推荐阅读
-
MySQL中主键为0与主键自排约束的关系详解(细节)
-
Python中MySQLdb和torndb模块对MySQL的断连问题处理
-
MySQL中通过EXPLAIN如何分析SQL的执行计划详解
-
Java中关于int和Integer的区别详解
-
详解微信开发中snsapi_base和snsapi_userinfo及静默授权的实现
-
MySQL中的LOCATE和POSITION函数使用方法
-
MySQL数据库8——数据库中函数的应用详解
-
从MySQL全库备份中恢复某个库和某张表的方法
-
详解HTML5中div和section以及article的区别
-
Android MotionEvent中getX()和getRawX()的区别实例详解