Android Sqlite資料庫多表聯合查詢

2021-08-20 15:09:56 字數 1532 閱讀 3727

工作上用資料庫儲存檔案還是很便利的,所以有時候發現一張表儲存資料感覺資料結構不是很清晰的時候,就需要新加第二張表或者多張表來進行聯合查詢物件信,一般是用鍵將彼此聯絡起來,在表中,每個主鍵的值都是唯一的。這樣做的目的是在不重複每個表中的所有資料的情況下,把表間的資料交叉**在一起,下面,寫一點簡單的例子:

先說一下兩張表各自要展現的內容有哪些

第一張表:

第二張表:

create table [customer](

[custno] integer primary key,

[company] char(30),

[addr1] char(30),

[addr2] char(30),

[city] char(15),

[state] char(20),

[zip] char(10),

[country] char(20),

[phone] char(15),

[fax] char(15),

[taxrate] float,

[contact] char(20),

[lastinvoicedate] datetime);

下面進行關聯查詢:

select customer.lastinvoicedate 

from custoly

inner join customer

on custoly.custno = 86433 and customer.custno = 86433

order by customer.taxrate

查詢結果意圖如下:

android sqlite 資料儲存

android 專門提供了乙個sqliteopenhelper幫助類,管理資料庫,借助這個類可以對資料庫進行建立和公升級。編寫藍芽配對列表寫入資料庫的helper類繼承抽象類sqliteopenhelper,用於建立資料庫和表bt pair devices public classbondeddev...

Android sqlite 資料型別

場景 一直做金融行業專案,所以資料的精確性十分重要 執行 查詢資料 資料精確到小數點2位 和直接執行sql所查詢資料不一致,經排查發現 value cursor.getstring cursor.getcolumnindex ss i 在作怪,此方法對double資料進行了怎樣處理,還需深究 解決方...

android SQLite大資料插入優化

sqlitedatabase db this.getwritabledatabase 獲取資料庫可寫物件 db.begintransaction 啟動事務 try 以上資料操作全部成功,通過標記settransactionsuccessful為true,事務才提交,否則回滾 預設標記為false d...