Back to Practice
#0385

Cancellation Rate by Category

MediumSQL24 min20 XP

Problem

Return category and cancel_rate as cancelled orders divided by total 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

orders(order_id INTEGER, category TEXT, status TEXT)

Examples

Example 1
InputA has 1 cancelled out of 2
OutputA 0.5, B 0

The numerator counts cancelled rows inside each category.

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
InputA has 1 cancelled out of 2
Expected[["A",0.5],["B",0]]

The numerator counts cancelled rows inside each category.

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