postgresql偏移特定列

时间:2015-08-19 16:01:17

标签: sql postgresql

如何在ArticleId特定偏移量之后选择作为开始

e.g start from 28 get 28, 27, 26

offset = 28;
limit = 3;

var query = 'SELECT * FROM "Article" ORDER BY "PublishDate" DESC LIMIT $2 OFFSET $1';

ArticleId | PublishDate

25 | "2015-08-19 15:33:37"
26 | "2015-08-19 17:05:42"
27 | "2015-08-19 17:06:05"
28 | "2015-08-19 17:06:22"
29 | "2015-07-19 17:06:46"
30 | "2015-08-19 17:08:11"

2 个答案:

答案 0 :(得分:1)

由于它是ArticleId的值,您可以在where子句中执行此操作

SELECT * 
FROM Article 
where ArticleId >= 28 and ArticleId <= 28 + 3

或如果ArticleId不连续

SELECT * 
FROM Article 
where ArticleId >= 28 
Order by ArticleId Limit 3 

答案 1 :(得分:1)

&#34;偏移&#34;只是你应该在你的WHERE子句中限制的ArticleId:

FrameLayout