Interview Question Bank · COUNT(*) vs COUNT(column) · NULL in the denominator
2. Driver acceptance rate
EasyRide-sharingQuestion #122
Concept: COUNT(*) vs COUNT(column) · NULL in the denominatorshow
A rate is the matching events divided by all events, and NULLs are the usual way the denominator goes wrong. COUNT(*) counts every row, while COUNT(column) quietly skips rows where that column is NULL. Decide what a NULL means for the business first, then pick the COUNT that matches it.
Example (different data):
SELECT agent_id, COUNT(*) AS tickets, COUNT(closed_at) AS closed, ROUND(100.0 * COUNT(closed_at) / COUNT(*), 1) AS closed_pct FROM support_tickets GROUP BY agent_id;
Your task
Rydora's dispatch team suspects some drivers let ride offers time out instead of declining them, which hides how often they turn rides down.
Return driver_id, city, offers (every offer sent to the driver), accepted, and acceptance_pct (accepted as a percentage of offers, ROUND(..., 1)). A NULL response means the offer timed out, which counts as an offer that wasn't accepted. Sort by acceptance_pct highest first, then driver_id.
Starting Postgres in your browser…
Checking your access…