我需要使用表t2中的new_id列更新表t1中old_id的列值,其中old_id在表t2中匹配
T1
old_id name desc
-----------------------
1 a abc
2 b def
3 c adf
null d ghi
T2
new_id old_id code
----------------------
x 1 ab
y 2 cd
z 3 gh
我的输出应该是
T1
old_id name desc
-----------------------
x a abc
y b def
z c adf
null d ghi
答案 0 :(得分:0)
尝试使用
update t1 set t1.old_id=(select min(t2.new_id) from t2 where t2.old_id=t1.old_id)
或
update t1 set t1.old_id=(select max(t2.new_id) from t2 where t2.old_id=t1.old_id)
要查看将使用此查询进行的更改
select t1.*, (select max(t2.new_id) from t2 where t2.old_id=t1=old_id) as futureIdvalue from t1
答案 1 :(得分:0)
在开始的几个假设:
这是我的代码(最后的更新声明)。
CREATE TABLE T1
( "old_id" VARCHAR2(50),
"name" VARCHAR2(50),
"desc" VARCHAR2(50)
);
/
CREATE TABLE T2
(
"new_id" VARCHAR2(50),
"old_id" VARCHAR2(50),
"code" VARCHAR2(50)
);
/
INSERT INTO T1 VALUES('1', 'a', 'abc');
INSERT INTO T1 VALUES('2', 'b', 'def');
INSERT INTO T1 VALUES('3', 'c', 'adf');
INSERT INTO T1 VALUES(NULL, 'd', 'ghi');
INSERT INTO T2 VALUES('x', '1', 'ab');
INSERT INTO T2 VALUES('y', '2', 'cd');
INSERT INTO T2 VALUES('z', '3', 'gh');
UPDATE t1
SET "old_id" = (SELECT "new_id"
FROM t2
WHERE t1."old_id" = t2."old_id");
答案 2 :(得分:-1)
.header_wrap .header .nav {
text-align: center;
}