中国开发网: 论坛: 程序员情感CBD: 贴子 152110
疯子张
忙得午饭也没吃,测试出informix还是支持update from 的语法的,不过写法比较麻烦。
infomix语法测试。

create table test1
(
id int,
counter1 int,
counter2 int,
counter3 int
);

insert into test1(id,counter1,counter2,counter3) values (1,0,0,0);
insert into test1(id,counter1,counter2,counter3) values (2,0,0,0);
insert into test1(id,counter1,counter2,counter3) values (3,0,0,0);
insert into test1(id,counter1,counter2,counter3) values (4,0,0,0);

create table test2
(
id int,
counter1 int,
counter2 int
);

insert into test2(id,counter1,counter2) values (1,111,111);
insert into test2(id,counter1,counter2) values (2,222,222);
insert into test2(id,counter1,counter2) values (3,333,333);

update test1 set (counter1,counter2,counter3)=
((select counter1,counter2,counter1+counter2 from test2
where test2.id=test1.id))
where test1.id in (select id from test2)

select * from test1

执行结果:

id counter1 counter2 counter3

1 111 111 222
2 222 222 444
3 333 333 666
4 0 0 0

正是俺想要的结果,不过这个update的写法比较变态,远比MSSQL复杂,估计效率也不高。
几年前,技术抛弃了我;现在,我抛弃了技术。


相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录