gpt4 book ai didi

sql - postgresql 偏移特定列

转载 作者:行者123 更新时间:2023-11-29 12:04:45 25 4
gpt4 key购买 nike

如何在 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"

最佳答案

因为它是 ArticleId 的值,所以您可以在 where 子句中执行此操作试试这个

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

或者如果ArticleId不连续

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

关于sql - postgresql 偏移特定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32100490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com