Queries · q025 · Chief Operating Officer · week 1, night 1
“Over the last two years, how long does it take from order placed to delivered, and how much does that vary month to month?”
Fictional people at a fictional company, each played by a language-model agent. Who they are and what they are told
The manager, at the start of week 1
Subject: Getting my bearings on fulfillment — questions for this week
Hi Lena,
Thanks for taking these on. I'm new here and coming from the logistics side, so my first priority is understanding whether the delivery promise we make to shoppers actually holds up — that's the lens for most of what's below. Given the slot budget, here's what matters most, roughly in priority order:
What I'll use this for: I'm forming my first impressions of operational health in this area and want to walk into conversations with merchants and carrier partners armed with facts, not assumptions. I'd rather have a smaller number of really clear answers than a lot of surface-level ones — so if you need to cut scope to fit your slots this week, prioritize #1 and #2, and we can pick up the rest next week.
Thanks — looking forward to Friday's memo.
Priya
The analyst · week 1, night 1, request 1 of 3
Priya's top two priorities are (1) end-to-end delivery speed and its consistency/trend, and (2) how the last peak season held up. I'm spending all 3 slots tonight on those, leaving carriers/warehouses, inventory and returns for later nights once I've seen where the baseline numbers point. I'm defining "delivered" as order status = fulfilled with all linked shipments having a non-null delivered_at, and delivery time as placed_at -> last shipment delivered_at. Report 1 gives the 24-month trend + variability (median/p90/SLA-hit-rate) so I can see direction of travel and spread in one page. Report 2 cuts the same metrics by merchant for 2025 to see who is reliably fast vs. a coin toss. Report 3 looks at the most recent peak window (Oct-Dec 2025) weekly to see if speed degraded under volume and whether a backlog built up and cleared by year-end. I'll sanity-check all three against each other (e.g. does the peak-season weekly average line up with the Nov-Dec rows in the monthly trend) before going further.
The engineer · 1 dry run on the empty schema, then the submission
select cd.month_label as month, count(*) as orders_delivered, round(avg(dd.delivery_days)::numeric, 1) as avg_delivery_days, round(cast(percentile_cont(0.5) within group (order by dd.delivery_days) as numeric), 1) as median_delivery_days, round(cast(percentile_cont(0.9) within group (order by dd.delivery_days) as numeric), 1) as p90_delivery_days, round(100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*), 1) as pct_within_5_days from ( select o.id as order_id, o.placed_at, (cast( (select max(s.delivered_at) from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id) as date) - cast(o.placed_at as date)) as delivery_days from orders o where o.status = 'fulfilled' and o.placed_at >= timestamp '2024-01-01' and o.placed_at < timestamp '2026-01-01' and exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id ) and not exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id and s.delivered_at is null ) ) dd join calendar_days cd on cd.calendar_date = cast(dd.placed_at as date) group by cd.month_label order by cd.month_label
“Query compiles with the expected columns. Submitting.”
“Submitted. The report computes, per calendar month of placed_at (2024-01 through 2025-12), the count of fully-delivered fulfilled orders along with mean, median, p90 delivery days and the share delivered within 5 days — using calendar-day differences between order placement and the latest shipment delivery, restricted to orders where every linked shipment has a delivered_at.”
As Lena Hartmann saw it, from the small dataset the agents worked on
month | orders_delivered | avg_delivery_days | median_delivery_days | p90_delivery_days | pct_within_5_days --------+------------------+-------------------+----------------------+-------------------+------------------ 2024-01 | 1234 | 3.5 | 3.0 | 6.0 | 89.6 2024-02 | 1061 | 3.8 | 3.0 | 6.0 | 86.1 2024-03 | 1139 | 3.8 | 3.0 | 6.0 | 86.9 2024-04 | 1154 | 4.0 | 4.0 | 6.0 | 83.4 2024-05 | 1275 | 4.2 | 4.0 | 6.0 | 79.1 2024-06 | 1223 | 4.1 | 4.0 | 6.0 | 83.7 2024-07 | 1292 | 3.9 | 4.0 | 6.0 | 84.9 2024-08 | 1233 | 4.0 | 4.0 | 6.0 | 83.4 2024-09 | 1281 | 3.9 | 3.0 | 6.0 | 85.0 2024-10 | 1422 | 4.0 | 4.0 | 6.0 | 82.6 2024-11 | 1961 | 3.9 | 4.0 | 6.0 | 84.8 2024-12 | 2432 | 4.3 | 4.0 | 7.0 | 77.9 2025-01 | 1717 | 3.6 | 3.0 | 5.0 | 90.3 2025-02 | 1329 | 3.7 | 3.0 | 6.0 | 89.4 2025-03 | 1545 | 3.8 | 4.0 | 6.0 | 87.1 2025-04 | 1477 | 3.7 | 3.0 | 6.0 | 88.8 2025-05 | 1574 | 4.3 | 4.0 | 7.0 | 80.6 2025-06 | 1419 | 3.8 | 3.0 | 6.0 | 86.3 2025-07 | 1565 | 3.9 | 4.0 | 6.0 | 85.2 2025-08 | 1457 | 3.9 | 4.0 | 6.0 | 87.2 2025-09 | 1611 | 4.1 | 4.0 | 6.0 | 83.2 2025-10 | 1767 | 4.1 | 4.0 | 6.0 | 83.1 2025-11 | 2419 | 4.7 | 4.0 | 8.0 | 78.7 2025-12 | 2653 | 4.2 | 3.0 | 7.0 | 81.1 (24 rows)
The memo and the queries that followed; links found by title, so inferred
Later queries that build on this report:
Changed only where the benchmark needs the same result on every system
select cd.month_label as month, count(*) as orders_delivered, round(avg(dd.delivery_days)::numeric, 1) as avg_delivery_days, round(cast(percentile_cont(0.5) within group (order by dd.delivery_days) as numeric), 1) as median_delivery_days, round(cast(percentile_cont(0.9) within group (order by dd.delivery_days) as numeric), 1) as p90_delivery_days, round(100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*), 1) as pct_within_5_days avg(cast(dd.delivery_days as numeric(18,6))) as avg_delivery_days, {{percentile_cont(0.5, dd.delivery_days)}} as median_delivery_days, {{percentile_cont(0.9, dd.delivery_days)}} as p90_delivery_days, 100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*) as pct_within_5_daysfrom ( select o.id as order_id, o.placed_at, (cast( (select max(s.delivered_at) o.placed_at AS placed_at, {{date_diff_days(o.placed_at, (select max(s.delivered_at) from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id) as date) - cast(o.placed_at as date)) as delivery_days where f.order_id = o.id))}} as delivery_days from orders o where o.status = 'fulfilled' and o.placed_at >= timestamp '2024-01-01' and o.placed_at < timestamp '2026-01-01' and exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id ) and not exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id and s.delivered_at is null )) ddjoin calendar_days cd on cd.calendar_date = cast(dd.placed_at as date)group by cd.month_labelorder by cd.month_labelorder by cd.month_label NULLS LAST
select cd.month_label as month, count(*) as orders_delivered, avg(cast(dd.delivery_days as numeric(18,6))) as avg_delivery_days, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY dd.delivery_days) as median_delivery_days, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY dd.delivery_days) as p90_delivery_days, 100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*) as pct_within_5_days from ( select o.id as order_id, o.placed_at AS placed_at, DATE_DIFF('day', o.placed_at, (select max(s.delivered_at) from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id)) as delivery_days from orders o where o.status = 'fulfilled' and o.placed_at >= timestamp '2024-01-01' and o.placed_at < timestamp '2026-01-01' and exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id ) and not exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id and s.delivered_at is null ) ) dd join calendar_days cd on cd.calendar_date = cast(dd.placed_at as date) group by cd.month_label order by cd.month_label NULLS LAST
select cd.month_label as month, count(*) as orders_delivered, avg(cast(dd.delivery_days as numeric(18,6))) as avg_delivery_days, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY dd.delivery_days) as median_delivery_days, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY dd.delivery_days) as p90_delivery_days, 100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*) as pct_within_5_days from ( select o.id as order_id, o.placed_at AS placed_at, (CAST((select max(s.delivered_at) from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id) AS DATE) - CAST(o.placed_at AS DATE)) as delivery_days from orders o where o.status = 'fulfilled' and o.placed_at >= timestamp '2024-01-01' and o.placed_at < timestamp '2026-01-01' and exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id ) and not exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id and s.delivered_at is null ) ) dd join calendar_days cd on cd.calendar_date = cast(dd.placed_at as date) group by cd.month_label order by cd.month_label NULLS LAST
select cd.month_label as month, count(*) as orders_delivered, avg(cast(dd.delivery_days as numeric(18,6))) as avg_delivery_days, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY CAST(dd.delivery_days AS DOUBLE PRECISION)) as median_delivery_days, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY CAST(dd.delivery_days AS DOUBLE PRECISION)) as p90_delivery_days, 100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*) as pct_within_5_days from ( select o.id as order_id, o.placed_at AS placed_at, (CAST((select max(s.delivered_at) from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id) AS DATE) - CAST(o.placed_at AS DATE)) as delivery_days from orders o where o.status = 'fulfilled' and o.placed_at >= timestamp '2024-01-01' and o.placed_at < timestamp '2026-01-01' and exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id ) and not exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id and s.delivered_at is null ) ) dd join calendar_days cd on cd.calendar_date = cast(dd.placed_at as date) group by cd.month_label order by cd.month_label NULLS LAST
select cd.month_label as month, count(*) as orders_delivered, avg(cast(dd.delivery_days as numeric(18,6))) as avg_delivery_days, quantileExactInclusive(0.5)(toFloat64(dd.delivery_days)) as median_delivery_days, quantileExactInclusive(0.9)(toFloat64(dd.delivery_days)) as p90_delivery_days, 100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*) as pct_within_5_days from ( select o.id as order_id, o.placed_at AS placed_at, dateDiff('day', o.placed_at, (select max(s.delivered_at) from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id)) as delivery_days from orders o where o.status = 'fulfilled' and o.placed_at >= timestamp '2024-01-01' and o.placed_at < timestamp '2026-01-01' and exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id ) and not exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id and s.delivered_at is null ) ) dd join calendar_days cd on cd.calendar_date = cast(dd.placed_at as date) group by cd.month_label order by cd.month_label NULLS LAST
The agents' own records, as the role play wrote them; only the personal data of the person who ran it is redacted
Report request from Lena Hartmann (analyst for the Chief Operating Officer): Title: Delivery time trend, monthly (2024-2025) Question: Over the last two years, how long does it take from order placed to delivered, and how much does that vary month to month? Grain: one row per calendar month of order placement Columns: - month (YYYY-MM) - orders_delivered (count of orders fully delivered) - avg_delivery_days (mean, placed_at to final delivered_at) - median_delivery_days (p50) - p90_delivery_days - pct_within_5_days (share of delivered orders where delivery_days <= 5) Details: Grain: one row per month_label (from calendar_days) of orders.placed_at. Scope: orders with placed_at between 2024-01-01 and 2025-12-31 inclusive, status = 'fulfilled'. For each such order, compute delivery_days = DATEDIFF(day, orders.placed_at, max(shipments.delivered_at) across all shipments reachable via fulfillments.order_id = orders.id and shipments.fulfillment_id = fulfillments.id), only including orders where every shipment linked to that order has a non-null delivered_at (i.e. fully delivered, no partial). Exclude orders with no linked shipments. Round avg/median/p90 to 1 decimal place; pct_within_5_days as a percentage rounded to 1 decimal. Order by month ascending. Expect 24 rows. Check your query with the warehouse's dry_run tool, then hand it in with submit.
dry_runselect cd.month_label as month, count(*) as orders_delivered, round(avg(dd.delivery_days)::numeric, 1) as avg_delivery_days, round(cast(percentile_cont(0.5) within group (order by dd.delivery_days) as numeric), 1) as median_delivery_days, round(cast(percentile_cont(0.9) within group (order by dd.delivery_days) as numeric), 1) as p90_delivery_days, round(100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*), 1) as pct_within_5_days from ( select o.id as order_id, o.placed_at, (cast( (select max(s.delivered_at) from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id) as date) - cast(o.placed_at as date)) as delivery_days from orders o where o.status = 'fulfilled' and o.placed_at >= timestamp '2024-01-01' and o.placed_at < timestamp '2026-01-01' and exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id ) and not exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id and s.delivered_at is null ) ) dd join calendar_days cd on cd.calendar_date = cast(dd.placed_at as date) group by cd.month_label order by cd.month_label
STATUS: COMPILES (dry run on the empty schema, no data read) COLUMNS: month, orders_delivered, avg_delivery_days, median_delivery_days, p90_delivery_days, pct_within_5_days
submitselect cd.month_label as month, count(*) as orders_delivered, round(avg(dd.delivery_days)::numeric, 1) as avg_delivery_days, round(cast(percentile_cont(0.5) within group (order by dd.delivery_days) as numeric), 1) as median_delivery_days, round(cast(percentile_cont(0.9) within group (order by dd.delivery_days) as numeric), 1) as p90_delivery_days, round(100.0 * sum(case when dd.delivery_days <= 5 then 1 else 0 end) / count(*), 1) as pct_within_5_days from ( select o.id as order_id, o.placed_at, (cast( (select max(s.delivered_at) from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id) as date) - cast(o.placed_at as date)) as delivery_days from orders o where o.status = 'fulfilled' and o.placed_at >= timestamp '2024-01-01' and o.placed_at < timestamp '2026-01-01' and exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id ) and not exists ( select 1 from fulfillments f join shipments s on s.fulfillment_id = f.id where f.order_id = o.id and s.delivered_at is null ) ) dd join calendar_days cd on cd.calendar_date = cast(dd.placed_at as date) group by cd.month_label order by cd.month_label
Submitted to tonight's batch. Your work on this request is done.