Compute average order processing hours per fulfillment center

Quick Overview

Write a SQL query that reports the average processing time in whole hours for each fulfillment center, counting only fulfilled orders and rounding to two decimals. It tests timestamp arithmetic, NULL filtering and grouped aggregation.

Compute average order processing hours per fulfillment center

Company: Coinbase

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

The `orders` table records when each order was placed and when its fulfillment center finished it. For each `fulfillment_center`, compute the average processing time between `order_placed` and `order_fulfilled` in hours, reported as `avg_processing_hours` and rounded to 2 decimals. Only fulfilled orders count, meaning rows where `order_fulfilled IS NOT NULL`. Order the result by `fulfillment_center` ascending. An order's processing time is the number of complete hours between the two timestamps. Leftover minutes are dropped before averaging, so an order that took 2 hours and 59 minutes counts as 2 hours. ```hint Count the hours Convert each order's duration to complete hours before you average. Check what your expression returns for an order that took longer than one day. ``` ### Input Table(s) Table `orders` | Column | Type | Meaning | |---|---|---| | order_id | INT | Order identifier | | fulfillment_center | VARCHAR(100) | Center that handles the order, never NULL | | order_placed | TIMESTAMP | When the order was placed, never NULL | | order_fulfilled | TIMESTAMP | When the order was fulfilled, NULL while the order is still open | Primary key: `order_id`. ### Output Contract - Columns, in this order: `fulfillment_center`, `avg_processing_hours`. - One row per fulfillment center that has at least one fulfilled order. - `avg_processing_hours` is the mean of the per-order complete hours, rounded to 2 decimals. - Rows sorted by `fulfillment_center` ascending. Each center appears once, so this order is unique. ### Example Input `orders`: | order_id | fulfillment_center | order_placed | order_fulfilled | |---|---|---|---| | 1 | Center-A | 2024-01-01 08:00:00 | 2024-01-01 20:00:00 | | 2 | Center-A | 2024-01-02 10:00:00 | 2024-01-03 10:00:00 | | 3 | Center-B | 2024-01-01 06:00:00 | 2024-01-01 12:00:00 | | 4 | Center-B | 2024-01-03 14:00:00 | 2024-01-04 14:00:00 | | 5 | Center-A | 2024-01-04 09:00:00 | NULL | Expected output: | fulfillment_center | avg_processing_hours | |---|---| | Center-A | 18.00 | | Center-B | 15.00 | Center-A has two fulfilled orders that took 12 and 24 hours, so its average is 18. Order 5 has no fulfillment time and is left out. Center-B's orders took 6 and 24 hours, for an average of 15. ### Constraints and Clarifications - The table has at most 10,000 rows. - When `order_fulfilled` is not NULL it is greater than or equal to `order_placed`, so no duration is negative. An order fulfilled at the moment it was placed counts as 0 hours. - A center whose orders are all still open does not appear in the output. - The average of whole hours can still be fractional: two orders of 2 and 3 hours average to 2.50. - `order_id` is unique, so no order is counted twice. - `fulfillment_center` is a non-empty string.

Overview: Write a SQL query that reports the average processing time in whole hours for each fulfillment center, counting only fulfilled orders and rounding to two decimals. It tests timestamp arithmetic, NULL filtering and grouped aggregation.

Coinbase logo
Coinbase
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

The orders table records when each order was placed and when its fulfillment center finished it. For each fulfillment_center, compute the average processing time between order_placed and order_fulfilled in hours, reported as avg_processing_hours and rounded to 2 decimals. Only fulfilled orders count, meaning rows where order_fulfilled IS NOT NULL. Order the result by fulfillment_center ascending.

An order's processing time is the number of complete hours between the two timestamps. Leftover minutes are dropped before averaging, so an order that took 2 hours and 59 minutes counts as 2 hours.

Input Table(s)

Table orders

ColumnTypeMeaning
order_idINTOrder identifier
fulfillment_centerVARCHAR(100)Center that handles the order, never NULL
order_placedTIMESTAMPWhen the order was placed, never NULL
order_fulfilledTIMESTAMPWhen the order was fulfilled, NULL while the order is still open

Primary key: order_id.

Output Contract

  • Columns, in this order: fulfillment_center , avg_processing_hours .
  • One row per fulfillment center that has at least one fulfilled order.
  • avg_processing_hours is the mean of the per-order complete hours, rounded to 2 decimals.
  • Rows sorted by fulfillment_center ascending. Each center appears once, so this order is unique.

Example

Input orders:

order_idfulfillment_centerorder_placedorder_fulfilled
1Center-A2024-01-01 08:00:002024-01-01 20:00:00
2Center-A2024-01-02 10:00:002024-01-03 10:00:00
3Center-B2024-01-01 06:00:002024-01-01 12:00:00
4Center-B2024-01-03 14:00:002024-01-04 14:00:00
5Center-A2024-01-04 09:00:00NULL

Expected output:

fulfillment_centeravg_processing_hours
Center-A18.00
Center-B15.00

Center-A has two fulfilled orders that took 12 and 24 hours, so its average is 18. Order 5 has no fulfillment time and is left out. Center-B's orders took 6 and 24 hours, for an average of 15.

Constraints and Clarifications

  • The table has at most 10,000 rows.
  • When order_fulfilled is not NULL it is greater than or equal to order_placed , so no duration is negative. An order fulfilled at the moment it was placed counts as 0 hours.
  • A center whose orders are all still open does not appear in the output.
  • The average of whole hours can still be fractional: two orders of 2 and 3 hours average to 2.50.
  • order_id is unique, so no order is counted twice.
  • fulfillment_center is a non-empty string.