我的数据库中有一个表,其中包含三列:
Screen
、Icon
和Rank
,我正在尝试找到最干净的方法来实现以下目标:
我想找到所有行
WHERE Screen = "myScreen" and Rank > 5
,然后使排名比当前值少一,我通过以下函数中的 SQLite Manager 类在 Java 中执行此操作:
public void DeleteScreenIcon (int id, String screenName, int rank){
int screenID = getScreenID(screenName);
SQLiteDatabase db=this.getWritableDatabase();
db.delete(isLookUp, colScreenID + "=" + screenID + " and " +colIconID+ "="+id, null);
// HERE IS WHERE I NOW WANT TO DO THAT..
db.execSQL("update "+ isLookUp +" set "+colRank+ "=" +colRank+ " -1 "+" where " + colScreenID + "='" +screenName + "' and " + colRank +">" +rank);
db.close();
}
此更新应该可以解决问题:
UPDATE myTable
SET Rank = Rank - 1
WHERE Screen = "myScreen"
AND Rank > 5;