如何在Android中使用SQLite数据库将两列相乘?

时间:2011-11-14 11:30:25

标签: java android

我使用SQLiteOpenHelper创建了一个表:

public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(
                "CREATE TABLE " + DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_NAME + " TEXT NOT NULL, " +
                KEY_SWIMMERLAPS + " INT NOT NULL, " +
                KEY_SPONSOR + " DEC NOT NULL );"

                );

我如何使用SQLiteDatbase方法将赞助商的游泳圈数值乘以?

1 个答案:

答案 0 :(得分:1)

试试这个:

Cursor cursor = db.rawQuery("SELECT " + KEY_SWIMMERLAPS + " * " + KEY_SPONSOR + " AS result FROM " + DATABASE_TABLE, null);

if (cursor.moveToFirst()){
    Log.w("result", cursor.getDouble(0)+"");
}