-1

有人可以帮我吗:我有 5 个表的数据库:数据库图stat_list 表预先填充了 5 个值(Att、pass、TD、inter、pass)。我想在 android 中创建一个表,它将显示每个玩家表 Stat_list 中所有值的总和。非常感谢!

表格示例

4

1 回答 1

0
    String sQry = "SELECT * FROM Stat_list;";
    SQLiteDatabase db = null;
    int count = -1;
    Cursor cursor = null;
    try {
        db = SQLiteOpenHelper.getReadableDatabase();
        cursor = db.rawQuery(sQry, null);
        if (cursor.moveToFirst()) {
            do {
                int playerScore = Integer.parseInt(cursor.getString(1)) +
                                  Integer.parseInt(cursor.getString(2)) +
                                  Integer.parseInt(cursor.getString(3)) +
                                  Integer.parseInt(cursor.getString(4))
                 ContentValues playerScores = new ContentValues();

                 playerScores.put(THE_NAME_OF_THE_SCORE_COLUMN, playerScore);
                 try{
                     db.update(NAME_OF_TABLE_WITH_SUMMED_PLAYER_SCORES,playerScores, "PlayerName = " cursor.getString(1), null);
                    }catch(SQLiteException e){}
                 } 
                 while (cursor.moveToNext());
        }           
    }
    catch (SQLiteException e) {
        Log.d("SQL Error", e.getMessage());
    }
    finally { 
        cursor.close();
        db.close(); 
    }

上面的代码片段从数据库中提取信息,总结分数并将其插入另一个表中。不过,您必须输入特定的值,例如正确的列名和表名。

于 2012-09-27T16:38:54.070 回答