BasicsGROUP BYCOUNTGoogleAmazonMeta
Table
orders(order_id INT, user_id INT)
Task
From orders(order_id, user_id), return each user_id and their total order_count, ordered by user_id ASC.
Why It Matters: GROUP BY with COUNT(*) computes per-customer order frequency—the first step in RFM (Recency, Frequency, Monetary) segmentation.
Output columns: user_id, order_count
Example
Input — orders
| order_id | user_id |
|---|---|
| 1 | 2 |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
| 5 | 2 |
Expected Output
| user_id | order_count |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 1 |
Explanation: Groups orders by customer_id and tallies the number of rows belonging to each customer.
Requirements
- Exact output columns:
user_id,order_count - Row order: Exact
ORDER BYorder is checked by the grader. - Query type: Write a single read-only Standard SQL
SELECT(orWITH ... SELECT) query.
Constraints & Evaluation Criteria
- Return `user_id, order_count` ordered by `user_id ASC`.
Hints
SQL⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
orders (5 rows)
Expected Output / Criteria
3 row(s): (1, 1); (2, 3); (3, 1)