![](/img/trans.png)
[英]How to Delete a row from more than one table with one sql query where email id is same
[英]Android SQLITE! Query more than one data(columns) from the same table
public class DatabaseHelper4 extends SQLiteOpenHelper {
private final static String DBNAME = "Bidprice";
private final static int DBVERSION = 2;
SQLiteDatabase mDB2;
public final static String TBL_BID = "bidprice";
public final static String COL_BID_ID = BaseColumns._ID;
public final static String COL_BID_PRICE = "pricebid";
public final static String COL_BID_NAME = "namebid";
private String crt_tbl_bidprice = "CREATE TABLE IF NOT EXISTS " + TBL_BID + "(" +
COL_BID_ID + " INTEGER PRIMARY KEY, " +
COL_BID_PRICE + " TEXT, " +
COL_BID_NAME + " TEXT " +
")";
public DatabaseHelper4(Context context) {
super(context, DBNAME, null, DBVERSION);
mDB2 = this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(crt_tbl_bidprice);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public long addPrice(String price,String nameprice) {
ContentValues cv = new ContentValues();
cv.put(COL_BID_PRICE,price);
cv.put(COL_BID_NAME,nameprice);
return mDB2.insert(TBL_BID,null,cv);
}
public Cursor getLatestPrice() {
return mDB2.query(TBL_BID,null,null,null,null,null,COL_BID_PRICE + " DESC","1");
}
}
我正在嘗試從此數據庫的表中查詢多個數據(列)。 我該怎么辦?我相信它與我的getLatestPrice()函數中查詢語句的格式有關。
希望我能得到一些幫助。
對於新手兄弟,請在您的getLatestPrice部分嘗試類似的操作
public Cursor getLatestPrice() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from "+TBL_BID, null);
return res;
}
這將為您提供您現在所需的光標 ! 包含您想要的表中的所有數據! 如果您想獲取任何特定的專欄文章和其他內容,則必須先這樣做
public Cursor getLatestPrice() {
SQLiteDatabase db = this.getReadableDatabase();
String[] projection = {
COL_BID_PRICE,
COL_BID_NAME
};
Cursor res = db.query(
TBL_BID, // The table to query
projection, // The array of columns to return (pass null to get all)
null, // The columns for the WHERE clause
null, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
null // The sort order
);
return res;
}
有關更簡單的詳細信息和設置,請參閱此處的鏈接
有關適用於Android的此部分的更多高級信息和Google文檔,請參見! 鏈接到這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.