Comparando nomes com SOUNDEX()
Strings bagunçadas como 'Ilynois' em vez de 'Illinois' podem causar problemas na análise de dados. Por isso é importante detectá-las.
Ao analisar a tabela flight_statistics, você percebe que alguns statistician_name e statistician_surname estão escritos de formas diferentes, como Miriam Smith e Myriam Smyth. Você suspeita que existam mais diferenças assim e quer conferir todos esses nomes.
Você pensa em comparar os nomes dos estatísticos com SOUNDEX(). Se o resultado de SOUNDEX() for o mesmo, mas os textos comparados forem diferentes, você encontrará os dados que precisa limpar.
Este exercício faz parte do curso
Limpando dados em bancos de dados SQL Server
Instruções do exercício
- Selecione os valores distintos das colunas
statistician_nameestatistician_surnamedeS1. - Faça um inner join da tabela
flight_statisticscomoS2usandoSOUNDEX()para unir prenomes e sobrenomes com som semelhante. - Filtre os valores em que as colunas
statistician_nameestatistician_surnamesejam diferentes entreS1eS2, respectivamente.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
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.___