Reputation: 365
I am developing an android game. im using sqlite database. I have a table in which five score store. i want to calculate min of all score and replace min value with some other value? how can i achieve this?if there are more than one same score which are min i want replace only one?
Upvotes: 0
Views: 216
Reputation: 56925
Fire the below query to get Min Value.
Cursor c = db.query(MY_DATABASE_TABLE, new String[] { "min(" + KEY_ROWID + ")" }, null, null,null, null, null);
Here KEY_ROWID is your column name from which you want to find minimum value.
Get Minimum Value.
c.moveToFirst(); //ADD THIS!
int minValue = c.getInt(0);
After getting the minimum value update the value using query.
ContentValues args = new ContentValues();
args.put(KEY_ROWID, newValue);
db.update(MY_DATABASE_TABLE, args, KEY_ROWID + "=" + minValue , null);
Upvotes: 1