Compute a percentage from a CASE expression inside a SUM. The ratio pattern — repeat / total — that drives nearly every retention KPI in DTC.
Board ask. Of customers who've ever ordered from us, what fraction have ordered MORE than once? That's the repeat-customer rate — repeat / total — and it's the single number the board cares about for the retention story. Use `ecom_customers`. Return one row, one column: `repeat_rate_pct`, rounded to one decimal place. We'll come back to repeat purchases by month in mission 18.
| Column | Type | Key |
|---|---|---|
| customer_id | INT | PK |
| TEXT | ||
| first_name | TEXT | |
| last_name | TEXT | |
| accepts_marketing | INT | |
| country | TEXT | |
| created_date | TEXT | |
| total_orders | INT | |
| total_spent | REAL |
Each hint you reveal reduces the XP you can earn. Try the query first.
Repeat = customers with `total_orders >= 2`. Total = customers with `total_orders >= 1` (everyone in our seed has ordered at least once, but the brief still says 'who've ever ordered' so the gate matters).
`SUM(CASE WHEN total_orders >= 2 THEN 1 ELSE 0 END)` is the repeat count; `SUM(CASE WHEN total_orders >= 1 THEN 1 ELSE 0 END)` is the denominator.
Expected: 32 / 50 = 64.0%. Use `100.0 *` to force float math, and `ROUND(..., 1)` for the one-decimal target.