Count orders by status
Count all orders in each status, including pending and cancelled orders. Return status and order_count. Row order does not matter.
Output
statusorder_countquery.sql
DuckDB SQLRestoring your saved draft…
Run a query to see results.
Reveal solution & explanation
SELECT status, COUNT(*) AS order_count FROM orders GROUP BY status;
The aggregation grain is one row per status. COUNT(*) is not affected by unrelated nullable columns.
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.