Comparando nomes com DIFFERENCE()
No exercício anterior, você usou SOUNDEX() para verificar os nomes dos estatísticos na tabela flight_statistics.
Agora, você vai fazer algo semelhante, mas usando a função DIFFERENCE(). DIFFERENCE() retorna 4 quando há uma correspondência idêntica ou muito semelhante entre duas strings e 0 quando há pouca ou nenhuma semelhança.
Se o resultado de DIFFERENCE() entre duas strings for 4, mas os textos que você está comparando forem diferentes, você encontrará dados que precisam ser limpos.
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_statisticscomoS2com nomes e sobrenomes que soem semelhantes nos casos em que oDIFFERENCEentre a coluna de cada tabela seja 4. - Filtre os valores em que as colunas
statistician_nameestatistician_surnamesejam diferentes entre si emS1eS2, respectivamente.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
SELECT
-- First name and surnames of the statisticians
DISTINCT S1.___, S1.___
-- Join flight_statistics with itself
FROM ___ S1 INNER JOIN ___ S2
-- The DIFFERENCE of the first name and surname has to be equals to 4
ON ___(S1.___, S2.___) = 4
AND ___(S1.___, S2.___) = 4
-- The texts of the first name or the texts of the surname have to be different
WHERE S1.___ <> S2.___
OR S1.___ <> S2.___