我怎样才能减少SQLite表的int列

时间:2012-03-23 12:59:01

标签: java android sqlite

我的数据库中有一个包含三列的表: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,感谢任何帮助

1 个答案:

答案 0 :(得分:6)

此更新应该可以解决问题:

UPDATE myTable 
SET Rank = Rank - 1
WHERE Screen = "myScreen"
AND Rank > 5;