问题描述
我有一个表,该表存储将随着时间的推移添加到其中的值.当我想添加值时,我想在一个查询中而不是-
I have a table that stores a value that will be added to over time. When I want to add to the value I would like to do so in a single query rather than -
- 从数据库获取oldValue
- newValue = oldValue + X
-
使用newValue更新行
- Get oldValue from database
- newValue = oldValue + X
update row with newValue
$ query1 =从表WHERE id = thisID中选择值";$ result1 = mysql_query($ query1);while($ row = mysql_fetch_array($ result)){ $ oldValue = $ row ['value'];}$ newValue = $ oldValue + x$ query1 =更新表SET值= $ newValue WHERE id = thisID";
$query1 = "SELECT value FROM table WHERE id = thisID";$result1 = mysql_query($query1);while($row=mysql_fetch_array($result)) { $oldValue = $row['value'];}$newValue = $oldValue + x$query1 = "UPDATE table SET value = $newValue WHERE id = thisID";
这可以在单个查询中完成吗?
Can this be done in a single query?
推荐答案
UPDATE table SET value = value + x WHERE id = thisID
这篇关于如何通过在单个查询中添加MySQL数据库来更新MySQL数据库表中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!