BasicsCOUNTAggregationGoogleAmazonMeta
Table
orders(order_id INT, user_id INT)
Task
From orders(order_id, user_id), return a single row with total_orders (COUNT(*)) and unique_buyers (COUNT(DISTINCT user_id)).
Why It Matters: Distinguishing COUNT(*) (total events) from COUNT(DISTINCT user_id) (unique users) is one of the most tested SQL fundamentals.
Output columns: total_orders, unique_buyers
Example
Input — orders
| order_id | user_id |
|---|---|
| 1 | 10 |
| 2 | 10 |
| 3 | 20 |
| 4 | 30 |
| 5 | 20 |
Expected Output
| total_orders | unique_buyers |
|---|---|
| 5 | 3 |
Explanation: COUNT(*) counts every order row, while COUNT(DISTINCT user_id) counts each repeat customer only once.
Requirements
- Exact output columns:
total_orders,unique_buyers - 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 1 row with columns `total_orders, unique_buyers`.
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
1 row(s): (5, 3)