merge into TableA a
USING TableB b
ON (b.name_ID = a.name_id and b.place = a.place
and b.city=a.city)
when matched then update set a.status = b.status ,
a.updatedatetime = timestamp
where address is null;
update tablea a set
(a.status, a.updatedatetime) =
(Select b.status, timestamp
from tableb b
where b.name_id = a.name_id
and b.place = a.place
and b.city = a.city
)
where a.address is null;
此外,您可能需要添加另一个条件( exists )为了不更新行,您不想:
...
where a.address is null
--
and exists (select null
from tableb c
where c.name_id = a.name_id
and c.place = a.place
and c.city = a.city
);
UPDATE TableA a
SET (a.status, a.updatedatetime) = (SELECT b.status, timestamp
FROM TableB b
WHERE b.name_ID = a.name_id
AND b.place = a.place
AND b.city=a.city)
WHERE EXISTS (SELECT 1
FROM TableB b
WHERE b.name_ID = a.name_id
AND b.place = a.place
AND b.city=a.city)
AND address IS NULL;
2条答案
按热度按时间vuktfyat1#
可能是这样的:
此外,您可能需要添加另一个条件(
exists
)为了不更新行,您不想:bwntbbo32#
你可以试试下面-