Premium problem70. Cancellation Rate With the Right Denominator

Medium Locked

rides(ride_id, rider_id, status, requested_at)

For each day in September 2026 that has terminal rides, return the cancellation rate among rides that actually reached a terminal status, meaning 'completed' or 'cancelled'.

Rides still sitting at 'requested' or 'matched' are excluded from both the numerator and the denominator. Leaving them in the denominator understates the cancellation rate, which is why this one is worth getting right.

Return date, terminal_rides, cancelled_rides and cancellation_rate_pct rounded to two decimals, ordered by date.

Tables

rides

ride_id  rider_id  status     requested_at
-------  --------  ---------  ------------
1        1         completed  2026-09-01
2        2         cancelled  2026-09-01
3        3         completed  2026-09-02
4        4         cancelled  2026-09-02
5        5         requested  2026-09-02
6        6         matched    2026-09-02
7        7         requested  2026-09-02
8        8         matched    2026-09-03
... 1 more row(s)

Expected result

date        terminal_rides  cancelled_rides  cancellation_rate_pct
----------  --------------  ---------------  ---------------------
2026-09-01  2               1                50.00
2026-09-02  2               1                50.00

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query