2017-01-11 35 views
0

讓我們假設我們有一個表:我要總結第1列和第2列,並與和更換色譜柱1的值

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 

回答

1

這是真的:

Update TableName set col1 = col1 + col2 

但我認爲你必須添加另一列作爲Flag,以確定是否記錄更新或不。

有些東西一樣col3 int default 0

Update TableName set col1 = col1 + col2, col3 = 1 
Where col3 = 0 
相關問題