table_1
(
c1 int
,c2 int
,c3 int
);
insert into table_1 values (1,2,3);
update table_1
set c2 = c2 + 5 --c2's value suppose to be 7 now
,c3 = c2 + c1; --c3's value suppose to be 7 + 1 = 8 now
select c1, c2, c3 from table_1;
result: 1, 7, 3;
结果应该是:1,7,8。
但是c3的值仍然是3,没有改变。
抱歉我的英文。
答案 0 :(得分:1)
UPDATE
语句使用"之前的值#34;更新,即
c2 = c2 + 5 => 2 + 5 = 7
but
c3 = c2 + c1 => 1 + 2 = 3
执行如下:
SQL>create table table_1 ( c1 int ,c2 int ,c3 int );
SQL>insert into table_1 values (1,2,3);
SQL>update table_1
SQL& set c2 = c2 + 5 --c2's value is set to 7 now
SQL& ,c3 = c2 + c1; --c3's value is set to 2 + 1 = 3 now
1 row updated
SQL>select c1, c2, c3 from table_1;
c1 c2 c3
=========== =========== ===========
1 7 3
1 row found
您甚至可以在列之间移动值:
SQL>update table_1 set c3 = c2, c2 = c1, c1 = c3;
1 row updated
SQL>select c1, c2, c3 from table_1;
c1 c2 c3
=========== =========== ===========
3 1 7
1 row found
要逐个更新列,请使用单独的UPDATE
语句:
SQL>create table table_1 ( c1 int ,c2 int ,c3 int );
SQL>insert into table_1 values (1,2,3);
SQL>update table_1
SQL& set c2 = c2 + 5; -- c2's value suppose to be 7 now
1 row updated
SQL>update table_1
SQL& set c3 = c2 + c1; -- c3's value suppose to be 7 + 1 = 8 now
1 row updated
SQL>select * from table_1;
c1 c2 c3
=========== =========== ===========
1 7 8
1 row found