我的数据库中有一个表有三列:Screen,Icon和Rank:我试图找到最简洁的方法来实现以下功能.
我想找到所有行WHERE Screen =“myScreen”和Rank> 5 //然后使得排名第一小于当前值..我在Java中通过sqlite Manager类在以下函数中执行此操作:
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();
}
对不起,我不熟悉sql任何帮助表示赞赏
解决方法:
此更新应该可以解决问题:
UPDATE myTable
SET Rank = Rank - 1
WHERE Screen = "myScreen"
AND Rank > 5;