Lab*_*lan 6 sql sqlite android
我需要用一列作为同一表中其他两列的总和来更新表的每一行
像这样的东西
UPDATE table1 SET table1.column1 =每行的sum(table1.column1 + table1.column2)
我试过了
This is working for me
UPDATE table1 SET column1 =(SELECT SUM(column1 + column2) FROM table1 where rowid = 1) WHERE rowid = 1
Run Code Online (Sandbox Code Playgroud)
所以我可以通过首先选择所有rowId迭代每个rowid来做到这一点
for( all rowid as i){
UPDATE table1 SET column1 =(SELECT SUM(column1 + column2) FROM table1 where rowid = i) WHERE rowid = i
}
Run Code Online (Sandbox Code Playgroud)
但我需要在一个查询中对该表中的所有行执行操作
当我尝试:
update table1 set column1 = (select (column1 + column2) from table1 )
Run Code Online (Sandbox Code Playgroud)
这将把我想要做的一行的column1和column2的所有值相加
任何的想法?
我在sqLite for Android工作
Mar*_*ers 18
不需要循环或内部选择.试试这个:
UPDATE table1 SET column1 = column1 + column2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12536 次 |
| 最近记录: |