PostgreSQL数据库-分页sql--offset
select * from users order by score desc limit 3;--取成绩的前3名=====select * from users order by score desc limit 3 offset 0;--取成绩的前3名
select * from users order by score desc limit 3 offset 1;--从第二名开始往后取前三名。
这里要强调一点,pgsql数据库分页的时候,limit 和offset的位置是可以互换的,比方说我下面两条sql语句,最终的执行效果是相同的。
SELECT
*
FROM
T_EXAMINE_TASK
WHERE
ORDER_EXAM_PERSON IS NULL
AND TASK_STATUS = '02'
AND TASK_TYPE != '03' limit 2 offset 0;
SELECT
*
FROM
T_EXAMINE_TASK
WHERE
ORDER_EXAM_PERSON IS NULL
AND TASK_STATUS = '02'
AND TASK_TYPE != '03' offset 0 limit 2 ;
运行结果: