Informix - where 子句合并到
Informix - where clause with merge into
我正在使用 Informix Dynamic Server Version 12.10.FC9W1X2
。
我需要用另一个 table 中的字段更新 table。我正在尝试使用
MERGE INTO
语句,但我无法使用 WHERE CLAUSE
过滤掉正在更新的 table 中的信息,因为它会导致语法错误。我还尝试将 AND
添加到 WHEN MATCHED
,但它不起作用。
有什么办法吗?
这是我到目前为止的陈述,
MERGE INTO table1 as t1
USING table2 as t2
ON t1.some_no = t2.some
WHEN MATCHED
THEN
UPDATE SET t1.some_other_no = t2.some_other_no, is_processed = 'Y', resolution = 'AAA'
table1 的附加过滤器可以放在 ON 子句中。例如:
create table t1(col1 int, col2 int, col3 int);
insert into t1 values(1,1,1);
insert into t1 values(1,2,0);
insert into t1 values(1,3,0);
insert into t1 values(2,1,0);
insert into t1 values(3,1,1);
create table t2 (col1 int, col2 int);
insert into t2 values(1,5);
insert into t2 values(2,5);
insert into t2 values(3,5);
merge into t1
using t2
on
t1.col1 = t2.col1
AND t1.col3 = 1
when matched then
update set t1.col2 = t2.col2;
The above results in the following output when selecting from the t1 table
col1 col2 col3
1 5 1
1 2 0
1 3 0
2 1 0
3 5 1
我正在使用 Informix Dynamic Server Version 12.10.FC9W1X2
。
我需要用另一个 table 中的字段更新 table。我正在尝试使用
MERGE INTO
语句,但我无法使用 WHERE CLAUSE
过滤掉正在更新的 table 中的信息,因为它会导致语法错误。我还尝试将 AND
添加到 WHEN MATCHED
,但它不起作用。
有什么办法吗?
这是我到目前为止的陈述,
MERGE INTO table1 as t1
USING table2 as t2
ON t1.some_no = t2.some
WHEN MATCHED
THEN
UPDATE SET t1.some_other_no = t2.some_other_no, is_processed = 'Y', resolution = 'AAA'
table1 的附加过滤器可以放在 ON 子句中。例如:
create table t1(col1 int, col2 int, col3 int);
insert into t1 values(1,1,1);
insert into t1 values(1,2,0);
insert into t1 values(1,3,0);
insert into t1 values(2,1,0);
insert into t1 values(3,1,1);
create table t2 (col1 int, col2 int);
insert into t2 values(1,5);
insert into t2 values(2,5);
insert into t2 values(3,5);
merge into t1
using t2
on
t1.col1 = t2.col1
AND t1.col3 = 1
when matched then
update set t1.col2 = t2.col2;
The above results in the following output when selecting from the t1 table
col1 col2 col3
1 5 1
1 2 0
1 3 0
2 1 0
3 5 1