DB Olympics

Queries · q233 · Chief Operating Officer · week 2, night 1

Albion Parcel performance by origin warehouse, baseline vs collapse

“Is Albion Parcel's November-December breakdown concentrated in a specific warehouse/hub (or the merchants it serves), or did it hit all origins roughly equally?”

Manager · asked the questionPriya RamanChief Operating Officer. Came from a third-party logistics provider. Wants to know how reliable the delivery promise is that merchants make on Tidewick.
Analyst · planned the reportLena HartmannSkeptical: checks definitions and sanity totals before trusting a trend.
Engineer · wrote the SQLOmarPragmatic: the shortest correct query, aggregates first and joins dimensions afterwards, FILTER clauses for conditional counts.

Fictional people at a fictional company, each played by a language-model agent. Who they are and what they are told

  1. Priya Raman writes to Lena Hartmann

    The manager, at the start of week 2

    Subject: Carrier picture confirms it — now I want to know what we can actually fix

    Lena,

    This is exactly the clarity I was hoping for — "it's the carriers, not the warehouses" is a much more actionable story than "fulfillment is inconsistent." A few things jumped out, including from what Daniel's and Tomasz's teams posted this week, and I want to chase them down before we draft anything for merchants or carrier partners.

    What surprised me: Albion Parcel going from solid to broken in November and staying broken through December is different from Landfall and Lowlands, which sound like long-term weak performers we've just tolerated. One is a relationship we may need to end; the other looks like it could be an acute problem (capacity, a route, a depot) that might actually be fixable if we understood the trigger. I don't want to lump all three into one "bad carriers" conversation when they may need completely different responses.

    I also noticed Daniel's team's finding that "where's my order" tickets spike in lockstep with late deliveries each November/December — that's a direct line from the carrier problem to support cost and customer satisfaction, and I'd like to be able to say that explicitly in my own numbers rather than borrowing his.

    Questions for this week:

    1. Of the three weak carriers, which ones are tied to specific regions, lanes, or merchants, versus broadly weak everywhere? I want to know if Albion's November collapse was localized (a single hub, country, or set of merchants) or general — that tells us whether this is a "fix one bad link" problem or a "this carrier can't be trusted" problem.
    2. If we could bring our weak carriers up to the standard of our good ones, how much of our delivery unreliability would actually go away? I want a sense of the ceiling — is this 80% of our problem, or just the long tail?
    3. Can you give me a clean, non-censored view of whether we're genuinely behind on restocking from suppliers, or if that was a year-end timing artifact? You flagged this yourself — I'd like it resolved before I mention supplier reliability to anyone.
    4. Is there any sign that the picking discrepancies Tomasz's team flagged (concentrated in apparel/footwear) are contributing to delivery delays or failed promises — e.g., orders stalling or being corrected after the fact — or is that purely a shrinkage/accounting issue with no customer-facing effect? I want to know if it belongs in the same story as delivery reliability or is a separate track entirely.

    If it's a tight week, prioritize #1 and #2 — I want the carrier narrative airtight before I take it anywhere. Returns/restock cycle time can wait one more week if needed.

    Thanks, Priya

  2. Lena Hartmann plans the night

    The analyst · week 2, night 1, request 2 of 3

    Priya wants the carrier narrative airtight before it goes anywhere, and specifically wants to know whether Albion Parcel's November collapse is a localized, fixable problem (one hub/country/merchant) versus Landfall Freight and Lowlands Express being broadly, chronically weak (a relationship-ending problem). That's priority #1 and it needs its own evidence on both the destination side (country/region) and the origin side (warehouse/hub), split into the pre-collapse baseline (Jan-Oct) vs. the collapse window (Nov-Dec) for Albion specifically. I'm spending all 3 slots tonight on that, since getting this distinction right shapes two very different conversations with carrier partners. I'll tackle priority #2 (the reliability "ceiling" if weak carriers matched good ones) first thing tomorrow night, using a full-year, non-truncated carrier table I don't yet have cleanly. Priority #3 (clean PO backlog view) and #4 (picking discrepancies vs. delivery) will follow later this week as time allows, per Priya's own prioritization.

    Albion Parcel performance by origin warehouse, baseline vs collapse
    Question
    Is Albion Parcel's November-December breakdown concentrated in a specific warehouse/hub (or the merchants it serves), or did it hit all origins roughly equally?
    One row per
    origin warehouse and period, for Albion Parcel shipments only
    Columns
    • warehouse_name
    • tenant_name
    • period ('baseline' = shipped_at 2025-01-01 to 2025-10-31; 'collapse' = shipped_at 2025-11-01 to 2025-12-31)
    • shipments_shipped
    • avg_transit_days
    • pct_within_3_days
    • share_of_period_shipments_pct (this warehouse's shipments / all Albion shipments in that period, x100)
  3. Omar writes the SQL

    The engineer · 1 dry run on the empty schema, then the submission

    Dry run 1 · STATUS: COMPILES (dry run on the empty schema, no data read)
    WITH base AS (
      SELECT
        f.warehouse_id,
        w.name AS warehouse_name,
        t.name AS tenant_name,
        CASE
          WHEN s.shipped_at >= DATE '2025-01-01' AND s.shipped_at < DATE '2025-11-01' THEN 'baseline'
          WHEN s.shipped_at >= DATE '2025-11-01' AND s.shipped_at < DATE '2026-01-01' THEN 'collapse'
        END AS period,
        s.delivered_at,
        s.shipped_at
      FROM shipments s
      JOIN fulfillments f ON f.id = s.fulfillment_id
      JOIN warehouses w ON w.id = f.warehouse_id
      JOIN tenants t ON t.id = w.tenant_id
      WHERE s.carrier = 'Albion Parcel'
        AND s.shipped_at >= DATE '2025-01-01'
        AND s.shipped_at < DATE '2026-01-01'
    ),
    agg AS (
      SELECT
        warehouse_id,
        warehouse_name,
        tenant_name,
        period,
        COUNT(*) AS shipments_shipped,
        AVG(EXTRACT(EPOCH FROM (delivered_at - shipped_at)) / 86400.0) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days_raw,
        100.0 * COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND delivered_at - shipped_at <= INTERVAL '3 days')
          / NULLIF(COUNT(*) FILTER (WHERE delivered_at IS NOT NULL), 0) AS pct_within_3_days_raw
      FROM base
      WHERE period IS NOT NULL
      GROUP BY warehouse_id, warehouse_name, tenant_name, period
    ),
    period_totals AS (
      SELECT period, SUM(shipments_shipped) AS total_shipments
      FROM agg
      GROUP BY period
    ),
    qualified AS (
      SELECT warehouse_id
      FROM agg
      GROUP BY warehouse_id
      HAVING MAX(shipments_shipped) >= 10
    )
    SELECT
      a.warehouse_name,
      a.tenant_name,
      a.period,
      a.shipments_shipped,
      ROUND(a.avg_transit_days_raw, 2) AS avg_transit_days,
      ROUND(a.pct_within_3_days_raw, 1) AS pct_within_3_days,
      ROUND(100.0 * a.shipments_shipped / pt.total_shipments, 1) AS share_of_period_shipments_pct
    FROM agg a
    JOIN period_totals pt ON pt.period = a.period
    JOIN qualified q ON q.warehouse_id = a.warehouse_id
    ORDER BY a.warehouse_name ASC, CASE a.period WHEN 'baseline' THEN 0 ELSE 1 END

    “Query compiles and returns the expected columns. Submitting.”

    Submitted · the SQL of the last dry run, unchanged · Submitted to tonight's batch. Your work on this request is done.

    “Submitted. The report gives one row per origin warehouse × period (baseline vs. collapse) for Albion Parcel shipments, limited to warehouses with ≥10 shipments in at least one period, with shipment counts, average transit days, on-time share, and each warehouse's share of total Albion volume in that period — which should make it clear whether the breakdown is concentrated in specific hubs/merchants or spread broadly.”

  4. The report comes back overnight

    As Lena Hartmann saw it, from the small dataset the agents worked on

    warehouse_name                        | tenant_name                   | period   | shipments_shipped | avg_transit_days | pct_within_3_days | share_of_period_shipments_pct
    --------------------------------------+-------------------------------+----------+-------------------+------------------+-------------------+------------------------------
    Birmingham Fulfilment Centre          | Folio & Fern                  | baseline |                21 |             2.75 |              66.7 |                           1.0
    Birmingham Fulfilment Centre          | Folio & Fern                  | collapse |                 7 |             7.63 |              16.7 |                           1.3
    Bromley Fulfilment Centre             | Kibblewick                    | baseline |               240 |             2.28 |              77.1 |                          11.3
    Bromley Fulfilment Centre             | Petalcourt Beauty             | baseline |               226 |             2.26 |              79.6 |                          10.6
    Bromley Fulfilment Centre             | Kibblewick                    | collapse |                74 |             8.05 |              33.8 |                          13.5
    Bromley Fulfilment Centre             | Petalcourt Beauty             | collapse |                88 |            10.44 |              20.5 |                          16.1
    Cambridge Fulfilment Centre           | Thistlecombe                  | baseline |                18 |             2.15 |              83.3 |                           0.8
    Cambridge Fulfilment Centre           | Thistlecombe                  | collapse |                11 |            10.86 |              18.2 |                           2.0
    Dublin Fulfilment Centre              | Sourdough Club                | baseline |                59 |             2.26 |              76.3 |                           2.8
    Dublin Fulfilment Centre              | Sourdough Club                | collapse |                17 |             8.08 |              40.0 |                           3.1
    Exeter Fulfilment Centre              | Kayak Corner                  | baseline |                31 |             1.96 |              87.1 |                           1.5
    Exeter Fulfilment Centre              | Kayak Corner                  | collapse |                 7 |            17.48 |              14.3 |                           1.3
    Galway Fulfilment Centre              | Ballycorran Industrial Supply | baseline |                73 |             2.39 |              72.6 |                           3.4
    Galway Fulfilment Centre              | Ballycorran Industrial Supply | collapse |                19 |             9.04 |              26.3 |                           3.5
    Leeds Fulfilment Centre               | The Balm Room                 | baseline |                44 |             2.45 |              68.2 |                           2.1
    Leeds Fulfilment Centre               | The Balm Room                 | collapse |                14 |             8.95 |              21.4 |                           2.6
    Liverpool Fulfilment Centre           | Fennel & Flint                | baseline |               112 |             2.18 |              79.5 |                           5.3
    Liverpool Fulfilment Centre           | Fennel & Flint                | collapse |                56 |             9.16 |              30.9 |                          10.2
    Manchester Fulfilment Centre          | Willow & Wren                 | baseline |                30 |              2.0 |              83.3 |                           1.4
    Manchester Fulfilment Centre          | Haven Linen                   | baseline |                10 |             1.95 |              90.0 |                           0.5
    Manchester Fulfilment Centre          | Grind Collective              | baseline |               399 |             2.22 |              81.0 |                          18.7
    Manchester Fulfilment Centre          | Grind Collective              | collapse |               116 |             8.31 |              26.1 |                          21.2
    Manchester Fulfilment Centre          | Willow & Wren                 | collapse |                11 |             10.8 |              27.3 |                           2.0
    Manchester Fulfilment Centre          | Haven Linen                   | collapse |                 2 |            10.49 |               0.0 |                           0.4
    Newcastle upon Tyne Fulfilment Centre | Deskline Supplies             | baseline |                25 |             2.47 |              72.0 |                           1.2
    Newcastle upon Tyne Fulfilment Centre | Deskline Supplies             | collapse |                 5 |             8.32 |               0.0 |                           0.9
    Oxford Fulfilment Centre              | Tiny Atelier                  | baseline |                10 |             2.58 |              90.0 |                           0.5
    Oxford Fulfilment Centre              | Tiny Atelier                  | collapse |                 2 |             11.9 |              50.0 |                           0.4
    Preston Fulfilment Centre             | Rosehip Lab                   | baseline |                10 |             2.56 |              70.0 |                           0.5
    Preston Fulfilment Centre             | Rosehip Lab                   | collapse |                10 |             9.44 |              33.3 |                           1.8
    Reading Fulfilment Centre             | Marrowby & Vane               | baseline |               778 |             2.19 |              81.2 |                          36.5
    Reading Fulfilment Centre             | Marrowby & Vane               | collapse |                85 |              5.2 |              36.5 |                          15.5
    (32 rows)
  5. What came of it

    The memo and the queries that followed; links found by title, so inferred

    Later queries that build on this report:

    It builds on:

  6. It becomes benchmark query q233

    Changed only where the benchmark needs the same result on every system

    • determinismtie-breaker: warehouse names are not unique
    • numericsdocs/NUMERICS.md: rounding removed; results keep full precision
    • numericsdocs/NUMERICS.md: EXTRACT(EPOCH FROM (b - a)) cast to NUMERIC(18,6)
    • made explicita selected t.col gets AS col, its standard name made explicit (7×)
    • placeholderseconds between
    • determinismthe standard leaves the place of NULLs in a sort to the implementation: NULLS LAST ascending, NULLS FIRST descending, as in the reference results (3×)
    The benchmark text, against the submitted SQL
    WITH base AS (  SELECT    f.warehouse_id,    f.warehouse_id AS warehouse_id,    w.name AS warehouse_name,    t.name AS tenant_name,    CASE      WHEN s.shipped_at >= DATE '2025-01-01' AND s.shipped_at < DATE '2025-11-01' THEN 'baseline'      WHEN s.shipped_at >= DATE '2025-11-01' AND s.shipped_at < DATE '2026-01-01' THEN 'collapse'    END AS period,    s.delivered_at,    s.shipped_at    s.delivered_at AS delivered_at,    s.shipped_at AS shipped_at  FROM shipments s  JOIN fulfillments f ON f.id = s.fulfillment_id  JOIN warehouses w ON w.id = f.warehouse_id  JOIN tenants t ON t.id = w.tenant_id  WHERE s.carrier = 'Albion Parcel'    AND s.shipped_at >= DATE '2025-01-01'    AND s.shipped_at < DATE '2026-01-01'),agg AS (  SELECT    warehouse_id,    warehouse_name,    tenant_name,    period,    COUNT(*) AS shipments_shipped,    AVG(EXTRACT(EPOCH FROM (delivered_at - shipped_at)) / 86400.0) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days_raw,    AVG({{seconds_between(shipped_at, delivered_at)}} / 86400.0) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days_raw,    100.0 * COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND delivered_at - shipped_at <= INTERVAL '3 days')      / NULLIF(COUNT(*) FILTER (WHERE delivered_at IS NOT NULL), 0) AS pct_within_3_days_raw  FROM base  WHERE period IS NOT NULL  GROUP BY warehouse_id, warehouse_name, tenant_name, period),period_totals AS (  SELECT period, SUM(shipments_shipped) AS total_shipments  FROM agg  GROUP BY period),qualified AS (  SELECT warehouse_id  FROM agg  GROUP BY warehouse_id  HAVING MAX(shipments_shipped) >= 10)SELECT  a.warehouse_name,  a.tenant_name,  a.period,  a.shipments_shipped,  ROUND(a.avg_transit_days_raw, 2) AS avg_transit_days,  ROUND(a.pct_within_3_days_raw, 1) AS pct_within_3_days,  ROUND(100.0 * a.shipments_shipped / pt.total_shipments, 1) AS share_of_period_shipments_pct  a.warehouse_name AS warehouse_name,  a.tenant_name AS tenant_name,  a.period AS period,  a.shipments_shipped AS shipments_shipped,  a.avg_transit_days_raw AS avg_transit_days,  a.pct_within_3_days_raw AS pct_within_3_days,  100.0 * a.shipments_shipped / pt.total_shipments AS share_of_period_shipments_pctFROM agg aJOIN period_totals pt ON pt.period = a.periodJOIN qualified q ON q.warehouse_id = a.warehouse_idORDER BY a.warehouse_name ASC, CASE a.period WHEN 'baseline' THEN 0 ELSE 1 ENDORDER BY a.warehouse_name ASC NULLS LAST, CASE a.period WHEN 'baseline' THEN 0 ELSE 1 END NULLS LAST, a.warehouse_id NULLS LAST
    WITH base AS (
      SELECT
        f.warehouse_id AS warehouse_id,
        w.name AS warehouse_name,
        t.name AS tenant_name,
        CASE
          WHEN s.shipped_at >= DATE '2025-01-01' AND s.shipped_at < DATE '2025-11-01' THEN 'baseline'
          WHEN s.shipped_at >= DATE '2025-11-01' AND s.shipped_at < DATE '2026-01-01' THEN 'collapse'
        END AS period,
        s.delivered_at AS delivered_at,
        s.shipped_at AS shipped_at
      FROM shipments s
      JOIN fulfillments f ON f.id = s.fulfillment_id
      JOIN warehouses w ON w.id = f.warehouse_id
      JOIN tenants t ON t.id = w.tenant_id
      WHERE s.carrier = 'Albion Parcel'
        AND s.shipped_at >= DATE '2025-01-01'
        AND s.shipped_at < DATE '2026-01-01'
    ),
    agg AS (
      SELECT
        warehouse_id,
        warehouse_name,
        tenant_name,
        period,
        COUNT(*) AS shipments_shipped,
        AVG(CAST(EXTRACT(EPOCH FROM (delivered_at - shipped_at)) AS NUMERIC(18,6)) / 86400.0) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days_raw,
        100.0 * COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND delivered_at - shipped_at <= INTERVAL '3 days')
          / NULLIF(COUNT(*) FILTER (WHERE delivered_at IS NOT NULL), 0) AS pct_within_3_days_raw
      FROM base
      WHERE period IS NOT NULL
      GROUP BY warehouse_id, warehouse_name, tenant_name, period
    ),
    period_totals AS (
      SELECT period, SUM(shipments_shipped) AS total_shipments
      FROM agg
      GROUP BY period
    ),
    qualified AS (
      SELECT warehouse_id
      FROM agg
      GROUP BY warehouse_id
      HAVING MAX(shipments_shipped) >= 10
    )
    SELECT
      a.warehouse_name AS warehouse_name,
      a.tenant_name AS tenant_name,
      a.period AS period,
      a.shipments_shipped AS shipments_shipped,
      a.avg_transit_days_raw AS avg_transit_days,
      a.pct_within_3_days_raw AS pct_within_3_days,
      100.0 * a.shipments_shipped / pt.total_shipments AS share_of_period_shipments_pct
    FROM agg a
    JOIN period_totals pt ON pt.period = a.period
    JOIN qualified q ON q.warehouse_id = a.warehouse_id
    ORDER BY a.warehouse_name ASC NULLS LAST, CASE a.period WHEN 'baseline' THEN 0 ELSE 1 END NULLS LAST, a.warehouse_id NULLS LAST
    10 ms100 ms1 sHyper43.2 msDuckDB45.6 msGizmoSQL50.3 msclickhouse_brew242 msFirebolt678 msDataFusionwrong resultClickHouseerror
    • DataFusionrow 1: col 6: "80.2861445783132530120481927710843373493976" vs "100.0"
    • ClickHouseCode: 43. DB::Exception: No operation lessOrEquals between Decimal(18, 6) and IntervalDay: while executing 'FUNCTION lessOrEquals(minus(__table2.delivered_at, __table2.shipped_at) :: 20, _CAST(3_IntervalDay, 'IntervalDay'_String) :: 17) -> lessOrEquals(minus(__table2.delivered_at, __table2.shipped_a
  7. Everything, as recorded

    The agents' own records, as the role play wrote them; only the personal data of the person who ran it is redacted

    Omar's whole session, 7 turns
    • The request, as Omar received it
      Report request from Lena Hartmann (analyst for the Chief Operating Officer):
      
      Title: Albion Parcel performance by origin warehouse, baseline vs collapse
      Question: Is Albion Parcel's November-December breakdown concentrated in a specific warehouse/hub (or the merchants it serves), or did it hit all origins roughly equally?
      Grain: one row per origin warehouse and period, for Albion Parcel shipments only
      Columns:
      - warehouse_name
      - tenant_name
      - period ('baseline' = shipped_at 2025-01-01 to 2025-10-31; 'collapse' = shipped_at 2025-11-01 to 2025-12-31)
      - shipments_shipped
      - avg_transit_days
      - pct_within_3_days
      - share_of_period_shipments_pct (this warehouse's shipments / all Albion shipments in that period, x100)
      Details: Tables: shipments (carrier='Albion Parcel', shipped_at, delivered_at) joined via fulfillments (fulfillment_id, warehouse_id) -> warehouses (name, tenant_id) -> tenants (name). Same transit_days definition as the destination-country report. Round avg_transit_days to 2 decimals, pct columns to 1 decimal. Include only warehouses with at least 10 shipments in at least one of the two periods. Order by warehouse_name ascending, then period (baseline before collapse).
      
      Check your query with the warehouse's dry_run tool, then hand it in with submit.
    • Omar calls dry_run
      WITH base AS (
        SELECT
          f.warehouse_id,
          w.name AS warehouse_name,
          t.name AS tenant_name,
          CASE
            WHEN s.shipped_at >= DATE '2025-01-01' AND s.shipped_at < DATE '2025-11-01' THEN 'baseline'
            WHEN s.shipped_at >= DATE '2025-11-01' AND s.shipped_at < DATE '2026-01-01' THEN 'collapse'
          END AS period,
          s.delivered_at,
          s.shipped_at
        FROM shipments s
        JOIN fulfillments f ON f.id = s.fulfillment_id
        JOIN warehouses w ON w.id = f.warehouse_id
        JOIN tenants t ON t.id = w.tenant_id
        WHERE s.carrier = 'Albion Parcel'
          AND s.shipped_at >= DATE '2025-01-01'
          AND s.shipped_at < DATE '2026-01-01'
      ),
      agg AS (
        SELECT
          warehouse_id,
          warehouse_name,
          tenant_name,
          period,
          COUNT(*) AS shipments_shipped,
          AVG(EXTRACT(EPOCH FROM (delivered_at - shipped_at)) / 86400.0) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days_raw,
          100.0 * COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND delivered_at - shipped_at <= INTERVAL '3 days')
            / NULLIF(COUNT(*) FILTER (WHERE delivered_at IS NOT NULL), 0) AS pct_within_3_days_raw
        FROM base
        WHERE period IS NOT NULL
        GROUP BY warehouse_id, warehouse_name, tenant_name, period
      ),
      period_totals AS (
        SELECT period, SUM(shipments_shipped) AS total_shipments
        FROM agg
        GROUP BY period
      ),
      qualified AS (
        SELECT warehouse_id
        FROM agg
        GROUP BY warehouse_id
        HAVING MAX(shipments_shipped) >= 10
      )
      SELECT
        a.warehouse_name,
        a.tenant_name,
        a.period,
        a.shipments_shipped,
        ROUND(a.avg_transit_days_raw, 2) AS avg_transit_days,
        ROUND(a.pct_within_3_days_raw, 1) AS pct_within_3_days,
        ROUND(100.0 * a.shipments_shipped / pt.total_shipments, 1) AS share_of_period_shipments_pct
      FROM agg a
      JOIN period_totals pt ON pt.period = a.period
      JOIN qualified q ON q.warehouse_id = a.warehouse_id
      ORDER BY a.warehouse_name ASC, CASE a.period WHEN 'baseline' THEN 0 ELSE 1 END
    • The warehouse answers
      STATUS: COMPILES (dry run on the empty schema, no data read)
      COLUMNS: warehouse_name, tenant_name, period, shipments_shipped, avg_transit_days, pct_within_3_days, share_of_period_shipments_pct
    • OmarQuery compiles and returns the expected columns. Submitting.
    • Omar calls submit
      WITH base AS (
        SELECT
          f.warehouse_id,
          w.name AS warehouse_name,
          t.name AS tenant_name,
          CASE
            WHEN s.shipped_at >= DATE '2025-01-01' AND s.shipped_at < DATE '2025-11-01' THEN 'baseline'
            WHEN s.shipped_at >= DATE '2025-11-01' AND s.shipped_at < DATE '2026-01-01' THEN 'collapse'
          END AS period,
          s.delivered_at,
          s.shipped_at
        FROM shipments s
        JOIN fulfillments f ON f.id = s.fulfillment_id
        JOIN warehouses w ON w.id = f.warehouse_id
        JOIN tenants t ON t.id = w.tenant_id
        WHERE s.carrier = 'Albion Parcel'
          AND s.shipped_at >= DATE '2025-01-01'
          AND s.shipped_at < DATE '2026-01-01'
      ),
      agg AS (
        SELECT
          warehouse_id,
          warehouse_name,
          tenant_name,
          period,
          COUNT(*) AS shipments_shipped,
          AVG(EXTRACT(EPOCH FROM (delivered_at - shipped_at)) / 86400.0) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days_raw,
          100.0 * COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND delivered_at - shipped_at <= INTERVAL '3 days')
            / NULLIF(COUNT(*) FILTER (WHERE delivered_at IS NOT NULL), 0) AS pct_within_3_days_raw
        FROM base
        WHERE period IS NOT NULL
        GROUP BY warehouse_id, warehouse_name, tenant_name, period
      ),
      period_totals AS (
        SELECT period, SUM(shipments_shipped) AS total_shipments
        FROM agg
        GROUP BY period
      ),
      qualified AS (
        SELECT warehouse_id
        FROM agg
        GROUP BY warehouse_id
        HAVING MAX(shipments_shipped) >= 10
      )
      SELECT
        a.warehouse_name,
        a.tenant_name,
        a.period,
        a.shipments_shipped,
        ROUND(a.avg_transit_days_raw, 2) AS avg_transit_days,
        ROUND(a.pct_within_3_days_raw, 1) AS pct_within_3_days,
        ROUND(100.0 * a.shipments_shipped / pt.total_shipments, 1) AS share_of_period_shipments_pct
      FROM agg a
      JOIN period_totals pt ON pt.period = a.period
      JOIN qualified q ON q.warehouse_id = a.warehouse_id
      ORDER BY a.warehouse_name ASC, CASE a.period WHEN 'baseline' THEN 0 ELSE 1 END
    • The warehouse answers
      Submitted to tonight's batch. Your work on this request is done.
    • OmarSubmitted. The report gives one row per origin warehouse × period (baseline vs. collapse) for Albion Parcel shipments, limited to warehouses with ≥10 shipments in at least one period, with shipment counts, average transit days, on-time share, and each warehouse's share of total Albion volume in that period — which should make it clear whether the breakdown is concentrated in specific hubs/merchants or spread broadly.