SQL

UPPER and LOWER

Standardizing Text Case

The Problem

Same data entered differently:

  • "SALES", "sales", "Sales" → should be one value

The Solution

SELECT UPPER('hello')  -- returns 'HELLO'
SELECT LOWER('HELLO')  -- returns 'hello'

💡 Key Technique: GROUP BY a Function

You can GROUP BY a transformed value to merge variations:

SELECT LOWER(TRIM(source)) as standardized_source,
       COUNT(*) as lead_count
FROM leads
GROUP BY LOWER(TRIM(source));   -- "SALES", "sales", "Sales" all become "sales"

Your Task

Standardize the source column for analysis:

  • Show original source
  • Standardized source (lowercase, trimmed)
  • Count of leads per standardized source

Group by the standardized value. Order by count descending.

query.sql
Loading SQL engine...
Downloading SQL engine… (one-time)

Downloading SQL engine… (one-time)

This runs entirely in your browser and is cached for next time.