在同一个 Table 中用另一个值填充 Null 值

Filling in Null Value with Another Value in the same Table

我想使用 table 中已经存在的值来更新我的列,该列具有空值以填充。空属性 地址可以由具有相同parcel id 的其他行填写。我进行了查询,结果显示在合并列中。

现在,我希望合并列填写 属性 地址列。

parcelid            propertyaddress      parcelid_1        propertyaddress_1                                   coalesce
025 07 0 031.00 None                 025 07 0 031.00    410 ROSEHILL CT, GOODLETTSVILLE            410 ROSEHILL CT, GOODLETTSVILLE
026 01 0 069.00 None                 026 01 0 069.00    141 TWO MILE PIKE, GOODLETTSVILLE              141 TWO MILE PIKE, GOODLETTSVILLE
026 05 0 017.00 None                 026 05 0 017.00    208 EAST AVE, GOODLETTSVILLE               208 EAST AVE, GOODLETTSVILLE

我试过这个查询,但它只适用于 Microsoft sql studio。它不适用于 psql。我似乎无法让它工作。

Update a
SET PropertyAddress = COLEASE(a.PropertyAddress,b.PropertyAddress)
From PortfolioProject.dbo.NashvilleHousing a
JOIN PortfolioProject.dbo.NashvilleHousing b
    on a.ParcelID = b.ParcelID
    AND a.UniqueID <> b.UniqueID 
Where a.PropertyAddress is null

如何解决这个问题?

在 postgresql 语法中是这样的,并且合并似乎是不必要的,因为您正在检查 属性 地址是否为空:

UPDATE PortfolioProject.dbo.NashvilleHousing a 
SET PropertyAddress = b.PropertyAddress
FROM PortfolioProject.dbo.NashvilleHousing b
WHERE a.ParcelID = b.ParcelID
AND a.UniqueID <> b.UniqueID 
AND a.PropertyAddress is null