Layout

Count orders by status

PROBLEM 3 / 24 · BASICAll problems ↗

Count all orders in each status, including pending and cancelled orders. Return status and order_count. Row order does not matter.

Outputstatusorder_count

query.sql

DuckDB SQL

Restoring your saved draft…

⌘ / Ctrl + Enter to run

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

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