Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
From order_items, return three counts in one row: item_rows (all rows), distinct_orders (unique order_id), and distinct_skus (unique sku).
Result columns · in this order
item_rowsdistinct_ordersdistinct_skusHow to approach it
One row, three columns. COUNT(*) counts item rows; COUNT(DISTINCT order_id) counts the orders those items belong to.
Sample input
| order_id | sku | quantity | unit_price |
|---|---|---|---|
| 1001 | SKU-A | 1 | 80 |
| 1001 | SKU-B | 2 | 15 |
| 1001 | SKU-C | 1 | 120 |
| 1002 | SKU-C | 1 | 120 |
| 1002 | SKU-D | 1 | 20 |
| 1004 | SKU-A | 1 | 80 |
6 rows — all rows shown.
Expected output
| item_rows | distinct_orders | distinct_skus |
|---|---|---|
| 15 | 7 | 7 |
1 row — all rows shown.
Constraints
order_items is at item grain, so order_id repeats. Use COUNT(*) for rows and COUNT(DISTINCT ...) for unique entities. Alias the three columns exactly as item_rows, distinct_orders, and distinct_skus.
Expected skills
Understanding table grain and the difference between COUNT(*), COUNT(column), and COUNT(DISTINCT column).
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.