create table myTable (int i, int user_id, int a, int b, int c)
这些值是这样的。如何根据existin列计算列值
1, 1, 1, 1, 0
2, 1, 2, 2, 0
3, 2, 3, 3, 0
4, 2, 4, 4, 0
我想将列“c”更新为user_id = 1的“a”+“b”。我应该怎么做?
create table myTable (int i, int user_id, int a, int b, int c)
这些值是这样的。如何根据existin列计算列值
1, 1, 1, 1, 0
2, 1, 2, 2, 0
3, 2, 3, 3, 0
4, 2, 4, 4, 0
我想将列“c”更新为user_id = 1的“a”+“b”。我应该怎么做?
Select查询
SELECT a, b, (a+b) AS c FROM mytable where user_id=1;
UPDATE查询
UPDATE mytable SET c = a+b where user_id=1;
对于相提并论满足特殊记录:
update some_table set `c` = (`a`+`b`) where `user_id` = your_id;
对于所有:
update some_table set `c` = (`a`+`b`);
@M哈立德·朱奈德,谢谢! – AK47