DataLane

7. Cancel rate by country

mediumProNot started~12 minAggregation

Asked in screens shaped like: Uber, DoorDash, Lyft

Ops wants a cancel rate per country on one row: total orders, cancelled orders, and the ratio. The trap is integer division — cancelled / orders returns 0 in most engines unless you force a float.

Requirements

  • Columns: country, orders, cancelled, cancel_rate
  • orders is every row for that country, cancelled and completed alike
  • cancel_rate is cancelled / orders rounded to 4 decimals
  • Order by country

Expected output

country, orders, cancelled, cancel_rate

Row order is graded, so ORDER BY matters here.

SQL editor

Loading SQL engine…

Ctrl/Cmd + Enter submits

Run your query to see the result set.

Pro problem

Medium problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close