create table myTable (int i, int user_id, int a, int b, int c)
值是这样的。
1, 1, 1, 1, 0
2, 1, 2, 2, 0
3, 2, 3, 3, 0
4, 2, 4, 4, 0
我想要专栏" c"更新为" a" +" b" for user_id = 1.我该怎么做?
答案 0 :(得分:3)
答案 1 :(得分:1)
选择查询
SELECT a, b, (a+b) AS c FROM mytable where user_id=1;
更新查询
UPDATE mytable SET c = a+b where user_id=1;
答案 2 :(得分:1)
对于特定记录:
update some_table set `c` = (`a`+`b`) where `user_id` = your_id;
为了所有人:
update some_table set `c` = (`a`+`b`);