SQLite3(或通用SQL)检索查询结果的第n行 [英] SQLite3 (or general SQL) retrieve nth row of a query result
问题描述
关于SQLite3的快速问题(也可能是一般的SQLite)
quicky question on SQLite3 (may as well be general SQLite)
如何检索查询结果的第n行?
How can one retrieve the nth row of a query result?
row_id(或任何索引)在我的情况下不起作用,因为表包含带有数字的列.根据某些数据,查询需要未按asc/desc标准对数据进行排序或排序的数据.
row_id (or whichever index) won't work on my case, given that the tables contain a column with a number. Based on some data, the query needs the data unsorted or sorted by asc/desc criteria.
但是我可能需要快速检索第2行和第2行; 5个结果.
But I may need to quickly retrieve, say, rows 2 & 5 of the results.
因此,除了现在使用计数器实现sqlite3_step()== SQLITE_ROW之外,我不知道如何进行此操作.
So other than implementing a sqlite3_step()==SQLITE_ROW with a counter right now I have no idea on how to proceed with this.
由于性能问题,我不太喜欢这种解决方案.因此,如果有人可以放下暗示,我们将不胜感激.
And I don't like this solution too much because of performance issues. so if anyone can drop a hint that'd be highly appreciated.
问候 大卫
推荐答案
在查询中添加LIMIT 1
和OFFSET <n>
例如SELECT * FROM users LIMIT 1 OFFSET 5132;
add LIMIT 1
and OFFSET <n>
to the query
example SELECT * FROM users LIMIT 1 OFFSET 5132;
这篇关于SQLite3(或通用SQL)检索查询结果的第n行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!