Android分頁查詢

2021-10-07 13:07:45 字數 2371 閱讀 4142

android—sqlite分頁搜尋查詢

首先來給大家說一下資料庫查詢

1.查詢所有的資料

string sql

="select * from history"

;

2.倒序desc
string sql

="select * from "

+ historyhelper.table_name +

" order by "

+ historyhelper.id +

" desc "

;

3.分頁查詢limit,offset

這裡我們查詢12條,從0到11

string sql

="select * from "

+ historyhelper.table_name +

" limit 11 offset 0"

;

4.倒序分頁查詢
string sql

="select * from "

+ historyhelper.table_name +

" order by "

+ historyhelper.id +

" desc "

+" limit '"

+ pagecount +

"' offset '"+(

(page -1)

* pagecount)

+"'"

;

需要注意的是order by和desc要寫在limit前面,同時非字串的值需要加上』』,如" limit 『" + pagecount + "』";pagecount這個值我們就需要用』』

4.倒序分頁查詢

搜尋用where條件, like 運算子是用來匹配萬用字元指定模式的文字值

下面的sql語句我們匹配了我們資料表的time欄位是否包含s文字值

string sql

="select * from "

+ historyhelper.table_name +

" where "

+ historyhelper.

time

+" like '%"

+ s +

"%'"

+" order by "

+ historyhelper.id +

" desc "

+" limit '"

+ pagecount +

"' offset '"+(

(page -1)

* pagecount)

+"'"

;

5.原始碼

//如果我要去11-20的account表的資料 select * from account limit 9 offset 10; 以上語句表示從account表獲取資料,跳過10行,取9行

public

static list

gethistory

(activity context,

int pagecount,

int page));

if(cursor.

movetofirst()

)while

(cursor.

movetonext()

);} cursor.

close()

; db.

close()

;}catch

(exception e)

return carresultmap;

}

我們可以在搜尋框中做乙個標識,如果搜尋框沒有文字,我們使用上面的方法進行分頁載入,如果搜尋框有文字,我們則呼叫下面方法進行分頁查詢,和上面方法類似,多了乙個引數s,這樣即可以根據使用者輸入的文字s返回我們需要的資料

public

static list

getsearchhistory

(activity context,

int pagecount,

int page, string s));

if(cursor.

movetofirst()

)while

(cursor.

movetonext()

);} cursor.

close()

; db.

close()

;}catch

(exception e)

return carresultmap;

}

python分頁查詢 分頁查詢

分頁 使用select查詢時,如果結果集資料量很大,比如幾萬行資料,放在乙個頁面顯示的話資料量太大,不如分頁顯示,每次顯示100條。要實現分頁功能,實際上就是從結果集中顯示第1 100條記錄作為第1頁,顯示第101 200條記錄作為第2頁,以此類推。因此,分頁實際上就是從結果集中 擷取 出第m n條...

Mysql 分頁查詢 快照 Mysql分頁查詢優化

select from orders history where type 8 limit 1000,10 該條語句將會從表 orders history 中查詢offset 1000開始之後的10條資料,也就是第1001條到第1010條資料 1001 id 1010 資料表中的記錄預設使用主鍵 一...

mysql 分頁查詢 失效 mysql分頁查詢

比如每頁10條,分頁查詢 語法 select from table limit offset,rows offset指定要返回的第一行的偏移量,rows第二個指定返回行的最大數目。初始行的偏移量是0 不是1 select from table limit 0,10 第一頁 select from t...