假设我们有一张 table :
ID | col1 | col2
1 | 23 | 4
2 | 2 | 6
我想对 col1 和 col2 求和,并用该和替换 col1 的值:
ID | col1 | col2
1 | 27 | 4
2 | 8 | 6
您能告诉我如何使用 MySQL 进行查询吗?
在我看来,查询可能是:
Update TableName set col1 = col1 + col2
最佳答案
这是真的:
Update TableName set col1 = col1 + col2
但我认为您必须添加另一列作为Flag
来确定记录是否更新。
诸如col3 int default 0
之类的东西
Update TableName set col1 = col1 + col2, col3 = 1
Where col3 = 0
关于mysql - 我想对第 1 列和第 2 列求和,并用该总和替换第 1 列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41583498/