sql - Informix - 带有合并的 where 子句
问题描述
我正在使用Informix Dynamic Server Version 12.10.FC9W1X2
.
我需要使用来自不同表的字段更新表。我正在尝试使用
MERGE INTO
语句,但我无法使用 aWHERE CLAUSE
从正在更新的表中过滤掉信息,因为它会导致语法错误。我也尝试添加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
推荐阅读
- html - 可以引导 4 卡平铺背景图像吗
- python - Selenium 动态 ID 和类
- excel - 尽管单元格格式相同,但 Excel 无法正确比较日期
- css - React 教程 - css 未加载
- python - python - TypeError:只有整数标量数组可以转换为标量索引,为什么?
- sql - Oracle PL\SQL 使用两个日期之间的第二个最小值更新数据
- azure - 如何使用 MSAL.net 实现身份验证和授权
- mongodb - 通过 PM2 Runtime 使用 MongoDB 设置 Strapi
- java - 如何改组 ArrayList,但改组特定索引后保持不变?
- apache - 用于从 url 中删除部分目录的 Apache 重写规则