假设我有 COUNTRY |邮政编码
列。会有很多重复项,但大多数情况下,一些 COUNTRY
值将丢失,而 POSTAL CODE
将出现。如何在 POSTAL CODE
匹配的其他行中用 COUNTRY
的值填写 COUNTRY
?
之前
COUNTRY | POSTAL CODE
UK | ABCXYZ
NULL | ABCXYZ
之后
COUNTRY | POSTAL CODE
UK | ABCXYZ
UK | ABCXYZ
最佳答案
我认为下一次更新就是您所需要的:
update table a
set country = b.country
FROM (select DISTINCT country, postal_code from table where country is not null) b
where a.postal_code = b.postal_code
and a.country is not null;
关于sql - 如果 col b 的值匹配,则用 col a 的值填充 col a 的 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56183738/