Monthly completed revenue
Calculate completed-order revenue for each calendar month in January–June 2026. Return month as YYYY-MM and revenue_cents, sorted chronologically. Use ordered_at, not the payment or refund date.
Output
monthrevenue_centsquery.sql
DuckDB SQLRestoring your saved draft…
Run a query to see results.
Reveal solution & explanation
SELECT strftime(ordered_at, '%Y-%m') AS month, SUM(order_total_cents) AS revenue_cents FROM orders WHERE status = 'completed' GROUP BY 1 ORDER BY month;
This is order-date revenue, not net cash collections. Keeping the time basis explicit avoids mixing different financial questions.
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.