2010-05-06 39 views
1

iam有一个列表,如列表递增一个表列的数据|| mySql

id ||计数器

如果我做了什么(某些情况下)我想计数器的值(在特定ID)的一个增加,目前的IAM这样做:

//get current value 
    current_value = select counter from myTable where id='someValue' 

    // increase value 
    current_value++ 

    //update table with current value 
    update myTable set counter=current_value where id='someValue'; 

目前的IAM运行2个查询此,请建议我以某种方式一步到位。

回答

8

数据库只需运行数学:

update myTable set counter = counter + 1 where id = 'someValue';