Premium, premium, PREMIUM.Instead:
SELECT UPPER(TRIM(customer_type)) AS customer_type, COUNT(*) AS customer_count
FROM customers
GROUP BY UPPER(TRIM(customer_type));
Now logically equivalent values can be grouped together.
🧹 20. Cleaning Product Names
Suppose product names contain unnecessary spaces and inconsistent capitalization.
SELECT UPPER(TRIM(product_name)) AS cleaned_product_name FROM products;
You can also remove unwanted characters:
SELECT REPLACE(TRIM(product_name), '-', ' ') AS cleaned_product_name FROM products;
Example:
' wireless-earbuds ' can become wireless earbuds.💼 21. Real-World Business Example
Suppose an e-commerce company stores customer names inconsistently.
You have
' alice ', 'ALICE', 'Alice', ' alice'You can create a normalized version:
SELECT UPPER(TRIM(customer_name)) AS normalized_name FROM customers;
This produces
ALICE, ALICE, ALICE, ALICE.The cleaned value can be used for analysis or as part of a data-matching strategy.
String normalization alone does not guarantee that two records represent the same person.
🧩 22. Combining Multiple String Functions
SQL becomes particularly powerful when functions are combined.
SELECT UPPER(TRIM(customer_name)) AS cleaned_name FROM customers;
SELECT LOWER(TRIM(email)) AS cleaned_email FROM customers;