填补缺失值(I)
在上一个练习中,您查看了 IncidentState 列中的非缺失值。如果不想省略缺失值,而是将它们替换为其他值,该怎么办?您可以使用 ISNULL() 函数来实现。下面的示例把 Shape 列中所有缺失值都替换为单词 'Saucer':
SELECT Shape, ISNULL(Shape, 'Saucer') AS Shape2
FROM Incidents
您也可以使用 ISNULL(),将缺失值替换为来自另一列的值,而不是指定的字面量。
本练习是课程的一部分
SQL Server 中级
练习说明
- 编写一条 T-SQL 查询,只返回
IncidentState为缺失的行。 - 将
IncidentState列中的所有缺失值替换为City列中的值,并将新列命名为Location。
交互式实操练习
通过完成这段示例代码来试试这个练习。
-- Check the IncidentState column for missing values and replace them with the City column
SELECT IncidentState, ___ AS Location
FROM Incidents
-- Filter to only return missing values from IncidentState
WHERE ___ ___ ___