Layout

Average order value

PROBLEM 5 / 24 · BASICAll problems ↗

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.

Outputcompleted_order_countavg_order_cents

query.sql

DuckDB SQL

Restoring your saved draft…

⌘ / Ctrl + Enter to run

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_id
  • status completed / cancelled / pending

Fictional teaching data. Money is USD cents; timestamps are UTC.