COUNT(*) vs. COUNT(DISTINCT): Total Orders & Unique Buyers

Basics
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_iduser_id
110
210
320
430
520

Expected Output

total_ordersunique_buyers
53

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 BY order is checked by the grader.
  • Query type: Write a single read-only Standard SQL SELECT (or WITH ... SELECT) query.

Constraints & Evaluation Criteria

  • Return 1 row with columns `total_orders, unique_buyers`.

Hints

SQL
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
orders (5 rows)
Expected Output / Criteria
1 row(s): (5, 3)