In earlier posts we saw that a clear question comes before any query. Now we look at how to get there. A manager rarely writes a question a table can answer. A request such as "how many active customers do we have" is short, and each word hides a choice. On a table of orders, those choices change the number, so we settle them first, in writing.
The four parts to fix
- The metric is the number we report, such as the count of customers or the sum of revenue.
- The grain is what one row of the result stands for, such as one customer, one order or one day.
- The time window is the start and end dates, and whether the end date is included.
- The definition is the rule for what counts, such as which order statuses and which customers.
One request, three answers
This is a definition problem. We run the request on a 15-row orders table, with three reasonable readings of "active in October". The first counts customers with at least one paid order in October. The second also counts cancelled orders. The third widens the window to September and October.
-- 1. paid orders in October
SELECT COUNT(DISTINCT customer_id) AS active_customers
FROM orders
WHERE status = 'paid'
AND order_date >= '2026-10-01' AND order_date < '2026-11-01'; -- 6
-- 2. any order in October, cancelled included
SELECT COUNT(DISTINCT customer_id) AS active_customers
FROM orders
WHERE order_date >= '2026-10-01' AND order_date < '2026-11-01'; -- 7
-- 3. paid orders in September and October
SELECT COUNT(DISTINCT customer_id) AS active_customers
FROM orders
WHERE status = 'paid'
AND order_date >= '2026-09-01' AND order_date < '2026-11-01'; -- 8| Reading | Active customers |
|---|---|
| Paid orders, October | 6 |
| Any order, October | 7 |
| Paid orders, September and October | 8 |
The three answers are all correct. They answer three different questions. If the manager expects 6 and the report says 8, the report looks wrong, even though nothing is broken.
Grain: count customers, not rows
Grain decides what the count stands for. In September, the paid orders give 8 rows but only 6 different customers, because two customers ordered twice. Counting rows would report 8 active customers.
-- WRONG: counts orders, not customers
SELECT COUNT(*) AS active_customers
FROM orders
WHERE status = 'paid'
AND order_date >= '2026-09-01' AND order_date < '2026-10-01'; -- 8
-- right: counts different customers
SELECT COUNT(DISTINCT customer_id) AS active_customers
FROM orders
WHERE status = 'paid'
AND order_date >= '2026-09-01' AND order_date < '2026-10-01'; -- 6Write the question as one sentence
To record the four choices, we write one sentence and send it back to the person who asked. For our example, the sentence is "How many different customers placed at least one paid order between 1 October and 31 October 2026?" The answer is 6. A taxi driver does the same when he asks where exactly you are going before he starts the meter.
If the manager answers "yes, that is what I meant", we run the query. If the manager says "I also want cancelled orders", we have found the difference in a minute, before the report was built.
A short template
- How many (or how much) of which metric?
- Counted per what, such as per customer or per order?
- Between which dates, and is the end date included?
- Which rows count, and which are left out?


