我正在嘗試在缺少值的列中添加屬性地址。
由于相同的parcelID 也具有相同的PropertyAddress,因此我使用以下內容來標識具有相應屬性地址的公共地塊ID。
select n.UniqueID, n.ParcelID, n.PropertyAddress, n2.UniqueID, n2.ParcelID, n2.PropertyAddress, IFNULL(n.PropertyAddress,n2.PropertyAddress)
from Nashnew n
join Nashnew n2
on n.ParcelID = n2.ParcelID
where n2.PropertyAddress =''
and n.UniqueID != n2.UniqueID
我得到這個結果:

現在我想使用以下方法將 IFNULL(n.PropertyAddress,n2.PropertyAddress) 列中的資料添加到缺少的 PropertyAddress 單元格中:
UPDATE Nashnew
set propertyAddress = IFNULL(n.PropertyAddress,n2.PropertyAddress)
from Nashnew n
join Nashnew n2
on n.ParcelID = n2.ParcelID
and n.UniqueID != n2.UniqueID
where n2.PropertyAddress =''
但是,我得到了這個結果,其中所有行的所有 PropertyAddress 都相同。

如何將正確的 PropertyAddress 添加到
uj5u.com熱心網友回復:
使用UPDATE陳述句中的代碼,您實際上加入了兩倍的表Nashnew。
您還應該檢查PropertyAddress更新副本的列Nashnew是否為null空:
改成這樣:
UPDATE Nashnew AS n
SET propertyAddress = n2.PropertyAddress
FROM Nashnew AS n2
WHERE n.ParcelID = n2.ParcelID
AND n.UniqueID <> n2.UniqueID
AND COALESCE(n.PropertyAddress, '') = ''
AND COALESCE(n2.PropertyAddress, '') <> '';
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/311411.html
