開始使用免費開始

用 SOUNDEX() 比對姓名

像是把 'Illinois' 寫成 'Ilynois' 這樣的凌亂字串,會在分析資料時帶來問題。因此,事先偵測這些情況很重要。

你在分析 flight_statistics 資料表時發現,有些 statistician_namestatistician_surname 的寫法不同,例如 Miriam SmithMyriam Smyth。你擔心還有更多類似差異,所以想要全面檢查這些姓名。

你打算用 SOUNDEX() 來比較統計人員的姓名。如果 SOUNDEX() 的結果相同,但實際文字不同,就能找出需要清理的資料。

本練習屬於課程

在 SQL Server 資料庫中清理資料

檢視課程

練習說明

  • S1 選出 statistician_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.___
編輯並執行程式碼