March customers above $200
Find customers whose completed-order spending in March 2026 exceeds $200 in total. Return customer_id and spend_cents. Use a half-open timestamp range [March 1, April 1). This question concerns all March purchases, not just the first order. Row order does not matter.
Output
customer_idspend_centsquery.sql
DuckDB SQLRestoring your saved draft…
Run a query to see results.
Reveal solution & explanation
SELECT customer_id, SUM(order_total_cents) AS spend_cents FROM orders WHERE status = 'completed' AND ordered_at >= TIMESTAMP '2026-03-01' AND ordered_at < TIMESTAMP '2026-04-01' GROUP BY customer_id HAVING SUM(order_total_cents) > 20000;
A timestamp upper bound of March 31 at midnight can exclude the rest of that day. Half-open month ranges avoid this trap.
Data & schema
- order_id
- INTEGER · PK
- customer_id
- INTEGER
- ordered_at
- TIMESTAMP
- status
- VARCHAR
- order_total_cents
- INTEGER
Table notes & relationships
One row per order. Only completed orders count as revenue unless a question says otherwise. Times are UTC.
customer_id→ customers.customer_idstatuscompleted / cancelled / pending
Fictional teaching data. Money is USD cents; timestamps are UTC.