SQL study, 2026
Segmenting online store customers in SQL
Customers with four or more orders are a third of buyers and 54.4% of revenue.
CASE WHEN order_count = 1 THEN 'One-time buyer' WHEN order_count BETWEEN 2 AND 3 THEN 'Repeat buyer' ELSE 'Loyal customer (4+)' END AS segment
Share of buyersShare of revenue
A six-table retail schema with 620 orders and $112,344 in sales, analyzed with cohort and window-function queries.
The segment query splits buyers by how often they come back, then compares each group’s share of buyers with its share of revenue.
What I found
Loyal customers, with four or more orders, are a third of buyers (63 of 189) and bring in 54.4% of revenue. One-time buyers are 19% of buyers and 7.5% of revenue.
| Buyers analyzed | 189 |
|---|---|
| Loyal customers (4+ orders) | 33.3% of buyers |
| Their share of revenue | 54.4% |
| One-time buyers | 19.0% of buyers, 7.5% of revenue |
Query 2.4, rerun on the repository’s seed data on Oct 24, 2026. An earlier version of the repository’s README reported different shares; this rerun replaces them.
Next case study: Replacing a manual data pull at Coca-Cola