Calculate Order Request Metrics
DoorDashData Scientist · OnsiteLast updated
This question evaluates SQL and data-manipulation competencies for computing order-level metrics, including aggregations, joins, windowed event sequencing, timestamp/timezone handling, and NULL-aware comparisons.
You are working with DoorDash order and delivery-request data. Write SQL to answer the questions below.
Tables:
orders
order_idBIGINT, primary keycustomer_idBIGINTmerchant_idBIGINTdasher_idBIGINT, nullable until assignedcreated_at_utcTIMESTAMP, when the order was placeddelivered_at_utcTIMESTAMP, when the order was delivered; null if not deliveredorder_statusVARCHAR, values includecompleted,cancelled, andrefunded
delivery_requests
request_idBIGINT, primary keyorder_idBIGINT, foreign key toorders.order_iddasher_idBIGINT, Dasher who received the offerrequested_at_utcTIMESTAMP, when the offer/request was sentoffer_amount_centsINTEGER, guaranteed offer amount shown to the Dasherrequest_statusVARCHAR, values includeaccepted,declined,expired, andcancelled
Relationship and assumptions:
- One order can have zero or more delivery requests.
- Requests for the same order should be ordered by
requested_at_utc, breaking ties byrequest_id. - Analyze completed orders whose
created_at_utcfalls in a parameterized window[start_ts_utc, end_ts_utc). - All timestamps are stored in UTC. If a business-day filter is needed, convert to the
America/Los_Angelestimezone before filtering. - Parameters:
late_threshold_minutesandrequest_threshold.
Questions:
- Calculate the percentage of completed orders that were late, where a late order is defined as an order whose delivery time is more than
late_threshold_minutesaftercreated_at_utc.
- Required output columns:
total_completed_orders,late_orders,pct_late_orders.
- Calculate the percentage of completed orders that had at least
request_thresholddelivery requests. Also calculate the average number of delivery requests per completed order.
- Include completed orders with zero requests in the denominator.
- Required output columns:
total_completed_orders,orders_with_at_least_threshold_requests,pct_orders_with_at_least_threshold_requests,avg_requests_per_order.
- Calculate the percentage of completed orders that had at least one offer increase. An offer increase occurs when a request's
offer_amount_centsis greater than the immediately previous request'soffer_amount_centsfor the same order.
- Also calculate the average percentage offer increase across positive increase events, defined as
(current_offer_amount_cents - previous_offer_amount_cents) / previous_offer_amount_cents. - Exclude transitions where the previous offer amount is null or zero from the percentage-increase calculation.
- Required output columns:
total_completed_orders,orders_with_offer_increase,pct_orders_with_offer_increase,avg_pct_offer_increase.
Return one query or a set of queries that produces these outputs.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.