SQL Dojo Beta
Metric

Cancellation rate

Cancelled orders divided by all orders, as a percentage.
SELECT ROUND(100.0 * COUNT(*) FILTER (WHERE status = 'cancelled') / COUNT(*), 1)
FROM orders;
SELECT COUNT(*) AS orders,
       COUNT(*) FILTER (WHERE status = 'cancelled') AS cancelled,
       ROUND(100.0 * COUNT(*) FILTER (WHERE status = 'cancelled') / COUNT(*), 1) AS cancel_rate_pct
FROM orders;
orderscancelledcancel_rate_pct
25001496.0
Try it in Randori