最近面試被問了Sqlite如何進行分頁查詢。平時沒怎么用過,只回答了一種使用sql語句的方式,原來Android的SqliteDatabase封裝了方法實現(xiàn)分頁查詢
內(nèi)容來自參考資料,本文只用作自己的總結(jié),請閱讀原文
http://blog.csdn.net/duxingzhe2012729/article/details/52576815
1.使用SQL語句進行查詢
1.limit+offset
select * from userinfo limit 5 offset 0 order by id
使用SqliteDataBase
table="表命",
columns="要查詢的列名",
selection="查詢 條件",
selectionArgs="條件中用了占位符的參數(shù)",
groupBy="數(shù)據(jù)分組",
having="分組后的條件",
orderBy="排序方式",
limit="分頁查詢條件";
cursor=
db.query(TableName, null,
null, null,null,null,null,
"5,9");//"5,9",第6行開始,返回9行數(shù)據(jù)