如何在 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
您事先知道需要分配哪个值,因此您只需过滤应更新哪些行。exists
似乎足够了:
update t1
set date_from = date '2020-07-20'
where exists (
select 1 from t2 where t2.id = t1.id and t2.modified = date '2020-07-20'
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句