【发布时间】:2021-11-04 01:03:09
【问题描述】:
在发现每个唯一的 PropertyAddress 值后,我在 nashvillehousing 表上执行了自连接,以替换 PropertyAddress 列中的 NULL 值具有唯一的 ParcelID 值。
我正在关注的在线教程使用 SQL Server。不幸的是,我无法在我的电脑上安装它。
我正在尝试为以下 SQL Server 代码查找等效的 MySQL 代码。
UPDATE a
SET PropertyAddress = ISNULL(a.PropertyAddress, b.PropertyAddress)
FROM projectportfolio.nashvillehousing a
JOIN projectportfolio.nashvillehousing b
ON a.ParcelID = b.ParcelID
AND a.UniqueID != b.UniqueID
WHERE a.PropertyAddress IS NULL
【问题讨论】:
-
想想你的代码。如果您根据 NULL 筛选您选择的行,那么在设置值时没有充分的理由使用 ISNULL。 a.PropertyAddress 将始终为 NULL,并且您想用 b.PropertyAddress 包含的任何内容覆盖它。但是,您应该忽略 b.PropertyAddress 也是 NULL 的行,因为这在逻辑上不会改变任何内容。学习规则 - 不要执行无意义的更新。
标签: mysql sql sql-server