Postgresql limits the number of returned results

Postgresql limits the number of returned results

TOP-N query

-- TOP-N
select first_name,last_name,salary
from employees
order by salary
-- 获取前10行
fetch first 10 rows only;
-- 第二种方式获取前10行数据
select first_name,last_name,salary
from employees
order by salary
limit 10;
-- 
select first_name,last_name,salary
from employees
order by salary
-- 获取前10行(值相同的数据也返回,所以返回的数据可能超过10条)
fetch first 10 rows with ties;

Paging query

SELECT first_name, last_name, salary
 FROM employees
ORDER BY salary DESC
OFFSET 10 ROWS
-- OFFSET 表示先忽略掉多少行数据
FETCH FIRST 10 ROWS ONLY;
-- 使用 LIMIT 加上 OFFSET 同样可以实现分页效果:
SELECT first_name, last_name, salary
 FROM employees
ORDER BY salary DESC
LIMIT 10 OFFSET 20;

insert image description here

Summarize

insert image description here

Guess you like

Origin blog.csdn.net/Java_Fly1/article/details/132352834