Standardizing color names
In the previous exercise, the DIFFERENCE() function was used to identify colors that closely matched our desired representation of the color GRAY. However, this approach retained a number of records where the vehicle_color value may or may not be gray. Specifically, the string GR (green) has the same Soundex code as the string GRAY. Fortunately, records with these vehicle_color values can be excluded from the set of records that should be changed.
In this exercise, you will assign a consistent gray vehicle_color value by identifying similar strings that represent the same color. Again, the fuzzystrmatch module has already been installed for you.
Este exercício faz parte do curso
Cleaning Data in PostgreSQL Databases
Instruções do exercício
- Complete the
SETclause to assign'GRAY'as thevehicle_colorfor records with avehicle_colorvalue having a matching Soundex code to the Soundex code for'GRAY'. - Update the
WHEREclause of the subquery so that thesummons_numbervalues returned excludesummons_numbervalues from records with'GR'as thevehicle_colorvalue.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
UPDATE
parking_violation
SET
-- Update vehicle_color to `GRAY`
___ = ___
WHERE
summons_number IN (
SELECT
summons_number
FROM
parking_violation
WHERE
DIFFERENCE(vehicle_color, 'GRAY') = 4 AND
-- Filter out records that have GR as vehicle_color
___ != ___
);