Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Delivery Time by Region

Easy
SQL & Data ManipulationDate FunctionsJoinsAggregations
Asked 2mo ago|
Uber
Uber
Asked 5 times

Problem

QuickCart tracks delivery performance across shopper regions. Write a SQL query to find the average delivery time in hours per region for the last month using the orders and shoppers tables.

Requirements

  1. Join orders to shoppers using shopper_id
  2. Only include orders delivered in the previous calendar month based on delivered_at
  3. Exclude rows where delivered_at or placed_at is NULL
  4. Return region and avg_delivery_hours, rounded to 2 decimal places
  5. Sort results by avg_delivery_hours descending, then region ascending

Table Definitions

orders

columntypedescription
order_idINTUnique order identifier
shopper_idINTShopper who placed the order
placed_atTIMESTAMPTime the order was placed
delivered_atTIMESTAMPTime the order was delivered
order_statusVARCHAR(20)Current order status

shoppers

columntypedescription
shopper_idINTUnique shopper identifier
shopper_nameVARCHAR(100)Shopper name
regionVARCHAR(50)Shopper region
signup_channelVARCHAR(50)Acquisition channel

Schema

orders
ColumnTypeDescription
order_idPKINTPrimary key for each order
shopper_idINTReferences the shopper who placed the order
placed_atTIMESTAMPTimestamp when the order was placed
delivered_atTIMESTAMPTimestamp when the order was delivered
order_statusVARCHAR(20)Current order status
shoppers
ColumnTypeDescription
shopper_idPKINTPrimary key for each shopper
shopper_nameVARCHAR(100)Full name of the shopper
regionVARCHAR(50)Region assigned to the shopper
signup_channelVARCHAR(50)Marketing channel used during signup

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
SELECT ...
FROM ...
JOIN ... ON ...
GROUP BY ...
HAVING ...
ORDER BY ... DESC;
Sign up to unlock solutions
Gopuff Business Analyst Interview QuestionsPeloton interactive Supply Chain Analyst Interview QuestionsUber Applied Scientist Interview QuestionsDoorDash USA Data Scientist Interview QuestionsInstacart Operations Manager Interview Questions
Next questions
ZomatoSQL: Avg Delivery Time Per RestaurantMediumInstacartCompare Regional Delivery Trends Over TimeMediumInstacartAnalyze Delivery Performance with SubqueriesMedium
PostgreSQL