Average order value
Return one row with completed_order_count and avg_order_cents for completed orders. Round the average in cents to two decimal places. Do not average customer-level averages.
Output
completed_order_countavg_order_centsquery.sql
DuckDB SQLRestoring your saved draft…
Run a query to see results.
Reveal solution & explanation
SELECT COUNT(*) AS completed_order_count, ROUND(AVG(order_total_cents), 2) AS avg_order_cents FROM orders WHERE status = 'completed';
AVG is over orders, so frequent buyers contribute more orders. This is not average revenue per buyer.
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.