所以我有一個缺少 propertyaddress 值的表,盡管 ParcelID 列可用于標識該值。如何在 sqlite 中執行自聯接以使用其真實的 propoertyaddress 值更新 NULL 值?
我嘗試了以下代碼
SELECT a.ParcelID, a.PropertyAddress, b.ParcelID, b.PropertyAddress, IFNULL(a.PropertyAddress, b.PropertyAddress)
FROM housing_data a
JOIN housing_data b
ON a.ParcelID = b.ParcelID
AND a.[UniqueID] <> b.[UniqueID]
WHERE a.PropertyAddress is null;
UPDATE a
SET PropertyAddress = IFNULL(a.PropertyAddress, b.PropertyAddress)
FROM housing_data a
WHERE a.PropertyAddress IS NULL;
JOIN housing_data b
ON a.ParcelID = b.ParcelID
AND a.[UniqueID] <> b.[UniqueID]
此代碼引發錯誤
uj5u.com熱心網友回復:
如果您的 SQLite 版本是 3.33.0 ,您可以使用以下UPDATE FROM語法:
UPDATE housing_data AS d1
SET PropertyAddress = d2.PropertyAddress
FROM housing_data AS d2
WHERE d2.ParcelID = d1.ParcelID AND d1.PropertyAddress IS NULL AND d2.PropertyAddress IS NOT NULL;
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/363301.html
