D8LooPFocus modeCODE WORKSPACE
From order_items, return three counts in one row: item_rows (all rows), distinct_orders (unique order_id), and distinct_skus (unique sku).
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 |
Expected output
| item_rows | distinct_orders | distinct_skus |
|---|---|---|
| 15 | 7 | 7 |
Constraints
order_items is at item grain, so order_id repeats. Use COUNT(*) for rows and COUNT(DISTINCT ...) for unique entities. Alias the columns item_rows, distinct_orders, and distinct_skus.
Expected skills
Understanding table grain and the difference between COUNT(*), COUNT(column), and COUNT(DISTINCT column).
Run the SQL query to inspect preview rows.