Skip to the page
Tecyfy

SQL interview question · medium

Product says "the average delivery time is 2 days", but customers keep complaining about slow deliveries. What would you check in the data, and what would you report instead?

The short answerLook at the distribution, not just the mean.

The full answer

Look at the distribution, not just the mean. Delivery times are skewed: most orders arrive quickly, and a long tail takes a week or more. The mean is pulled by the tail but still hides it, and the customers who complain live in that tail. Report the median for the typical order and high percentiles (the 90th or 95th) for the slow ones, and break them down by region, carrier and warehouse.

Look at the distribution

SELECT
  COUNT(*)                                               AS orders,
  ROUND(AVG(delivery_days), 1)                           AS mean_days,
  percentile_cont(0.5)  WITHIN GROUP (ORDER BY delivery_days) AS median_days,
  percentile_cont(0.9)  WITHIN GROUP (ORDER BY delivery_days) AS p90_days,
  percentile_cont(0.99) WITHIN GROUP (ORDER BY delivery_days) AS p99_days,
  MAX(delivery_days)                                     AS max_days
FROM deliveries
WHERE shipped_at >= '2026-09-01' AND shipped_at < '2026-10-01';

A typical result: mean 2.1, median 1.5, p90 4, p99 11. The "average of 2 days" is true, and 1 order in 10 still takes twice that.

percentile_cont interpolates between values; percentile_disc returns an actual value from the data, which is easier to explain for whole days.

Break it down

SELECT region, carrier,
       COUNT(*) AS orders,
       percentile_cont(0.5) WITHIN GROUP (ORDER BY delivery_days) AS median_days,
       percentile_cont(0.9) WITHIN GROUP (ORDER BY delivery_days) AS p90_days
FROM deliveries
GROUP BY region, carrier
ORDER BY p90_days DESC;

The slow tail is rarely spread evenly. One carrier in one region often accounts for most of it.

Check the data, too

  • Missing deliveries: orders still in transit or lost have no delivery date and drop out of every average, though they are the worst cases. Count them separately.
  • What the clock measures: order to delivery, or shipping to delivery? Customers feel the first.
  • Weekends and holidays: calendar days or business days, stated in the metric.

What to report

A short line such as "half of orders arrive within 1.5 days; 90% within 4; 3% take over a week, mostly carrier X in region Y", plus a histogram or the share of orders over a promised threshold, such as "delivered within 3 days". A share against a promise is the number customers understand and the one teams can act on.

What interviewers want: knowing that the mean hides skew, medians and percentiles with percentile_cont, segmenting to find where the tail comes from, missing data, and reporting against a threshold users care about.

Last updated 16 October 2026

Sources

Where each fact comes from

  1. 1Aggregate functions