开始使用免费开始使用

使用 SOUNDEX() 比较姓名

像将 'Illinois' 写成 'Ilynois' 这样的脏字符串会给数据分析带来问题。因此,及时发现这些问题很重要。

在分析 flight_statistics 表时,您发现有些 statistician_namestatistician_surname 的写法不同,例如 Miriam SmithMyriam Smyth。您担心还有更多类似差异,所以想检查所有这些姓名。

您打算用 SOUNDEX() 来比较统计员的姓名。如果 SOUNDEX() 的结果相同,但实际文本不同,就能找到需要清理的数据。

本练习是课程的一部分

在 SQL Server 数据库中清洗数据

查看课程

练习说明

  • 选择 S1statistician_namestatistician_surname 列的去重值。
  • 使用 SOUNDEX() 对读音相近的名和姓进行匹配,将 flight_statistics 表以 S2 作为别名进行 INNER JOIN。
  • 过滤掉在 S1S2 中分别对应的 statistician_namestatistician_surname 完全相同的行,仅保留两边值不同的记录。

交互式实操练习

通过完成这段示例代码来试试这个练习。

SELECT 
    -- First name and surname of the statisticians
	DISTINCT S1.___, S1.___
-- Join flight_statistics with itself
FROM ___ S1 INNER JOIN ___ S2 
	-- The SOUNDEX result of the first name and surname have to be the same
	ON ___(S1.___) = ___(S2.___) 
	AND ___(S1.___) = ___(S2.___) 
-- The texts of the first name or the texts of the surname have to be different
WHERE S1.___ <> S2.___
	OR S1.___ <> S2.___
编辑并运行代码