During android development, we often save temporary data to the Sqlite database, and analyze and process the stored data at a certain point in time of the application.
In the actual development process, query statistics and other operations will appear, then we are familiar with the query method
CursorAndroid. database. sqlite. SQLiteDatabase. query (StringTable,String[] Columns,StringSelection,String[] SelectionArgs,StringGroupBy,StringHaving,StringOrderBy)
It cannot adapt to statistical analysis.
This reminds us of the ExecuteScalar interface in the development of other languages, which executes SQL statements and returns a row or column. The following is an example of implementing such a function in sqlite (mainly used
Cursor android. database. sqlite. SQLiteDatabase. rawQuery (String SQL, String [] selectionArgs)
Such an Interface
Instance:
public int GetSumScore()
{
int resultscore=0;
String sql=" select sum(Score) from tempAnswerGuess";
Cursor cursor=db.rawQuery(sql, null);
cursor.moveToFirst();
resultscore= Integer.parseInt(cursor.getString(0));
return resultscore;
}