Question:
Given an
orders table with the following columns:driver_id
order_time
delivered_time
Write an SQL query to calculate the average waiting/delivery time (in minutes) for each delivery partner.
โ SQL Solution (MySQL)
SELECT driver_id,AVG(TIMESTAMPDIFF(MINUTE, order_time, delivered_time)) AS avg_delivery_timeFROM ordersGROUP BY driver_id;๐ก Approach:
โข Calculate the time difference between
order_time and delivered_time.โข Convert the difference into minutes using
TIMESTAMPDIFF().โข Group records by
driver_id.โข Use
AVG() to find the average delivery time for each delivery partner.๐ Concepts Tested:
โข Date & Time Functions
โข GROUP BY
โข Aggregate Functions (
AVG)โข Business Metrics
React โฅ๏ธ for more real interview questions
