【发布时间】:2022-01-01 10:57:38
【问题描述】:
所以我有一个缺少 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]
此代码引发错误
【问题讨论】:
-
将
WHERE移到JOIN下方UPDATE
标签: sql sqlite join sql-update