【发布时间】:2021-11-28 16:23:21
【问题描述】:
我正在尝试在缺少值的列中添加属性地址。
我使用下面的方法来识别具有相应属性地址的常见宗地 ID,因为相同的宗地 ID 也具有相同的 PropertyAddress。
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 添加到
【问题讨论】:
-
在第二次查询中加入时,为什么加入的唯一 ID 不等于唯一 ID?
-
否则,当我加入表格时,会有重复的行。
标签: sql sqlite join sql-update sql-null