在20/07/20时如何使用“已修改”(t2)更新“ date_from”(t1)。
因此,在这种情况下,将在t1中更新ID的1和2,而ID 3保持不变。
表1:
id date_from
-----------------------
1 13/07/30
2 13/07/30
3 13/07/30
表2:
id name modified
-----------------------
1 x 20/07/20
2 y 20/07/20
3 z 19/05/10
答案 0 :(得分:1)
类似这样的东西:
update t1 a set
a.date_from = (select b.modified
from t2 b
where b.id = a.id
and b.modified = date '2020-07-20'
)
where exists (select null
from t2 c
where c.id = a.id
and c.modified = date '2020-07-20'
)
答案 1 :(得分:1)
您预先知道需要分配哪个值,因此您只需要过滤应更新的行。 __repr__()
似乎足够:
exists
答案 2 :(得分:1)
如果速度很重要,
merge into t1 trg
using
(
select id, modified
from t2
where modified = date'2020-07-20'
) src
on ( trg.id = src.id )
when matched then update
set trg.date_from = src.modified
where lnnvl(trg.date_from = src.modified);