Back to Practice
#0318

Customer Order Counts Including Zero

MediumSQL24 min20 XP

Problem

Return every customer name and their order_count, including customers with zero orders.

Why This Matters

SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.

Schema

customers(customer_id INTEGER, name TEXT); orders(order_id INTEGER, customer_id INTEGER)

Examples

Example 1
InputCara has no orders
OutputCara -> 0

COUNT(o.order_id) ignores NULL joined rows, so unmatched customers get 0.

Constraints

  • Return only the requested columns.
  • Use deterministic ORDER BY when multiple rows are returned.
  • Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
InputCara has no orders
Expected[["Asha",2],["Ben",1],["Cara",0]]

COUNT(o.order_id) ignores NULL joined rows, so unmatched customers get 0.

Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks