postgreSQL数据库limit分页、排序

postgreSQL数据库limit分页、排序

语法:


  1. select * from persons limit  A  offset  B;

解释:

A就是你需要多少行;

B就是查询的起点位置。

示例:


  1. select * from persons limit 5 offset 0 ;

意思是,起点0开始查询,返回5条数据。


  1. select * from persons limit 5 offset 5 ;

意思是,起点5开始查询,返回5条数据。

 特殊:


  1. select * from persons limit 5 ;​

这个就类似:


  1. select * from persons limit 5 offset 0;

也就是,从起点0开始查询,返回5条数据。

 按规则排序,同时也要分页:


  1. select * from persons
  2. order by lastname
  3. limit 5 offset 0;​
原文地址:https://www.cnblogs.com/yangcx666/p/8723763.html