例子
# select * from COMPANY;
id | name | age | address | salary
----+-------+-----+-----------+--------
1 | Paul | 32 | California| 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall| 45000
7 | James | 24 | Houston | 10000
(7 rows)
以下是一个示例,它根据您要从表中获取的行数限制表中的行 -
testdb=# SELECT * FROM COMPANY LIMIT 4;
这将产生以下结果 -
id | name | age | address | salary
----+-------+-----+-------------+--------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
(4 rows)
但是,在某些情况下,您可能需要从特定偏移量中提取一组记录。这是一个示例,它从第三个位置开始获取三个记录 -
testdb=# SELECT * FROM COMPANY LIMIT 3 OFFSET 2;
这将产生以下结果 -
id | name | age | address | salary
----+-------+-----+-----------+--------
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
(3 rows)