DB Olympics

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

Landfall Freight & Lowlands Express performance by destination country, full year 2025

“Are our two chronically weak carriers bad everywhere, or concentrated on specific lanes/countries?”

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 3 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.

    Landfall Freight & Lowlands Express performance by destination country, full year 2025
    Question
    Are our two chronically weak carriers bad everywhere, or concentrated on specific lanes/countries?
    One row per
    carrier and destination country (Landfall Freight and Lowlands Express only), full year 2025
    Columns
    • carrier
    • destination_country
    • shipments_shipped
    • avg_transit_days
    • pct_within_3_days
    • share_of_carrier_shipments_pct (this country's shipments / that carrier's total 2025 shipments, 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
        s.carrier,
        co.name AS destination_country,
        s.id AS shipment_id,
        s.delivered_at,
        (CAST(s.delivered_at AS date) - CAST(s.shipped_at AS date)) AS transit_days
      FROM shipments s
      JOIN fulfillments f ON f.id = s.fulfillment_id
      JOIN orders o ON o.id = f.order_id
      JOIN addresses a ON a.id = o.shipping_address_id
      JOIN countries co ON co.id = a.country_id
      WHERE s.carrier IN ('Landfall Freight','Lowlands Express')
        AND s.shipped_at >= TIMESTAMP '2025-01-01'
        AND s.shipped_at < TIMESTAMP '2026-01-01'
    ),
    carrier_totals AS (
      SELECT carrier, COUNT(*) AS carrier_shipments
      FROM base
      GROUP BY carrier
    ),
    country_stats AS (
      SELECT
        carrier,
        destination_country,
        COUNT(*) AS shipments_shipped,
        AVG(transit_days) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days,
        COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND transit_days <= 3) AS within_3_count
      FROM base
      GROUP BY carrier, destination_country
    )
    SELECT
      cs.carrier,
      cs.destination_country,
      cs.shipments_shipped,
      ROUND(cs.avg_transit_days, 2) AS avg_transit_days,
      ROUND(100.0 * cs.within_3_count / cs.shipments_shipped, 1) AS pct_within_3_days,
      ROUND(100.0 * cs.shipments_shipped / ct.carrier_shipments, 1) AS share_of_carrier_shipments_pct
    FROM country_stats cs
    JOIN carrier_totals ct ON ct.carrier = cs.carrier
    WHERE cs.shipments_shipped >= 15
    ORDER BY cs.carrier ASC, cs.shipments_shipped DESC, cs.destination_country ASC

    “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. Summary of choices made where the request left room for interpretation: - avg_transit_days: averaged only over delivered shipments (as specified, since transit_days requires a delivery date). - pct_within_3_days: numerator is delivered shipments with transit_days ≤ 3, denominator is shipments_shipped (total shipped in that carrier/country) — so undelivered shipments count against the on-time rate rather than being excluded. - share_of_carrier_shipments_pct: denominator is each carrier's full 2025 shipment count across all destination countries, not just the countries that cleared the 15-shipment reporting threshold — so the shares reflect true concentration even if they don't sum to 100% across the printed rows. These are noted in the submit note for Lena.”

  4. The report comes back overnight

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

    carrier          | destination_country | shipments_shipped | avg_transit_days | pct_within_3_days | share_of_carrier_shipments_pct
    -----------------+---------------------+-------------------+------------------+-------------------+-------------------------------
    Landfall Freight | Ireland             |               233 |             4.28 |              29.2 |                           12.2
    Landfall Freight | Belgium             |               187 |             4.34 |              26.7 |                            9.8
    Landfall Freight | Netherlands         |               182 |             5.94 |              19.8 |                            9.5
    Landfall Freight | Germany             |               177 |             6.15 |              14.1 |                            9.3
    Landfall Freight | Austria             |               161 |              4.3 |              29.2 |                            8.4
    Landfall Freight | United Kingdom      |               147 |             4.32 |              32.7 |                            7.7
    Landfall Freight | United States       |               141 |             4.79 |              24.8 |                            7.4
    Landfall Freight | Switzerland         |               139 |             4.42 |              25.9 |                            7.3
    Landfall Freight | France              |               120 |             6.37 |              17.5 |                            6.3
    Landfall Freight | Canada              |                85 |              4.2 |              37.6 |                            4.5
    Landfall Freight | Poland              |                62 |             4.18 |              35.5 |                            3.3
    Landfall Freight | Finland             |                56 |             6.04 |              19.6 |                            2.9
    Landfall Freight | Australia           |                45 |             4.73 |              20.0 |                            2.4
    Landfall Freight | Luxembourg          |                42 |             3.95 |              31.0 |                            2.2
    Landfall Freight | Norway              |                36 |             4.19 |              25.0 |                            1.9
    Landfall Freight | Sweden              |                29 |             5.54 |               6.9 |                            1.5
    Landfall Freight | Denmark             |                28 |             6.07 |              25.0 |                            1.5
    Landfall Freight | Italy               |                18 |             4.39 |              27.8 |                            0.9
    Lowlands Express | Netherlands         |              1002 |             2.73 |              79.9 |                           39.1
    Lowlands Express | Belgium             |               440 |             2.81 |              69.3 |                           17.2
    Lowlands Express | France              |               211 |             3.69 |              63.0 |                            8.2
    Lowlands Express | Ireland             |               154 |             4.42 |              27.3 |                            6.0
    Lowlands Express | Austria             |               130 |             4.29 |              26.2 |                            5.1
    Lowlands Express | Germany             |               124 |             6.15 |              16.9 |                            4.8
    Lowlands Express | Switzerland         |               108 |              4.4 |              25.0 |                            4.2
    Lowlands Express | United States       |                91 |             4.52 |              27.5 |                            3.6
    Lowlands Express | United Kingdom      |                84 |             4.39 |              32.1 |                            3.3
    Lowlands Express | Poland              |                42 |             4.56 |              23.8 |                            1.6
    Lowlands Express | Finland             |                36 |             6.31 |              16.7 |                            1.4
    Lowlands Express | Luxembourg          |                32 |             4.58 |              15.6 |                            1.2
    Lowlands Express | Denmark             |                25 |             5.54 |              20.0 |                            1.0
    Lowlands Express | Norway              |                22 |             4.32 |              36.4 |                            0.9
    Lowlands Express | Sweden              |                21 |             6.71 |              14.3 |                            0.8
    Lowlands Express | Australia           |                20 |             4.95 |              20.0 |                            0.8
    (34 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 q234

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

    • numericsdocs/NUMERICS.md: AVG over an integer computed as a decimal: AVG(CAST(x AS NUMERIC(18,6)))
    • numericsdocs/NUMERICS.md: rounding removed; results keep full precision
    • made explicita selected t.col gets AS col, its standard name made explicit (5×)
    • placeholderdate diff days
    • 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    s.carrier,    s.carrier AS carrier,    co.name AS destination_country,    s.id AS shipment_id,    s.delivered_at,    (CAST(s.delivered_at AS date) - CAST(s.shipped_at AS date)) AS transit_days    s.delivered_at AS delivered_at,    {{date_diff_days(s.shipped_at, s.delivered_at)}} AS transit_days  FROM shipments s  JOIN fulfillments f ON f.id = s.fulfillment_id  JOIN orders o ON o.id = f.order_id  JOIN addresses a ON a.id = o.shipping_address_id  JOIN countries co ON co.id = a.country_id  WHERE s.carrier IN ('Landfall Freight','Lowlands Express')    AND s.shipped_at >= TIMESTAMP '2025-01-01'    AND s.shipped_at < TIMESTAMP '2026-01-01'),carrier_totals AS (  SELECT carrier, COUNT(*) AS carrier_shipments  FROM base  GROUP BY carrier),country_stats AS (  SELECT    carrier,    destination_country,    COUNT(*) AS shipments_shipped,    AVG(transit_days) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days,    AVG(CAST(transit_days AS NUMERIC(18,6))) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days,    COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND transit_days <= 3) AS within_3_count  FROM base  GROUP BY carrier, destination_country)SELECT  cs.carrier,  cs.destination_country,  cs.shipments_shipped,  ROUND(cs.avg_transit_days, 2) AS avg_transit_days,  ROUND(100.0 * cs.within_3_count / cs.shipments_shipped, 1) AS pct_within_3_days,  ROUND(100.0 * cs.shipments_shipped / ct.carrier_shipments, 1) AS share_of_carrier_shipments_pct  cs.carrier AS carrier,  cs.destination_country AS destination_country,  cs.shipments_shipped AS shipments_shipped,  cs.avg_transit_days AS avg_transit_days,  100.0 * cs.within_3_count / cs.shipments_shipped AS pct_within_3_days,  100.0 * cs.shipments_shipped / ct.carrier_shipments AS share_of_carrier_shipments_pctFROM country_stats csJOIN carrier_totals ct ON ct.carrier = cs.carrierWHERE cs.shipments_shipped >= 15ORDER BY cs.carrier ASC, cs.shipments_shipped DESC, cs.destination_country ASCORDER BY cs.carrier ASC NULLS LAST, cs.shipments_shipped DESC NULLS FIRST, cs.destination_country ASC NULLS LAST
    WITH base AS (
      SELECT
        s.carrier AS carrier,
        co.name AS destination_country,
        s.id AS shipment_id,
        s.delivered_at AS delivered_at,
        DATE_DIFF('day', s.shipped_at, s.delivered_at) AS transit_days
      FROM shipments s
      JOIN fulfillments f ON f.id = s.fulfillment_id
      JOIN orders o ON o.id = f.order_id
      JOIN addresses a ON a.id = o.shipping_address_id
      JOIN countries co ON co.id = a.country_id
      WHERE s.carrier IN ('Landfall Freight','Lowlands Express')
        AND s.shipped_at >= TIMESTAMP '2025-01-01'
        AND s.shipped_at < TIMESTAMP '2026-01-01'
    ),
    carrier_totals AS (
      SELECT carrier, COUNT(*) AS carrier_shipments
      FROM base
      GROUP BY carrier
    ),
    country_stats AS (
      SELECT
        carrier,
        destination_country,
        COUNT(*) AS shipments_shipped,
        AVG(CAST(transit_days AS NUMERIC(18,6))) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days,
        COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND transit_days <= 3) AS within_3_count
      FROM base
      GROUP BY carrier, destination_country
    )
    SELECT
      cs.carrier AS carrier,
      cs.destination_country AS destination_country,
      cs.shipments_shipped AS shipments_shipped,
      cs.avg_transit_days AS avg_transit_days,
      100.0 * cs.within_3_count / cs.shipments_shipped AS pct_within_3_days,
      100.0 * cs.shipments_shipped / ct.carrier_shipments AS share_of_carrier_shipments_pct
    FROM country_stats cs
    JOIN carrier_totals ct ON ct.carrier = cs.carrier
    WHERE cs.shipments_shipped >= 15
    ORDER BY cs.carrier ASC NULLS LAST, cs.shipments_shipped DESC NULLS FIRST, cs.destination_country ASC NULLS LAST
    100 ms1 sHyper155 msDuckDB176 msGizmoSQL176 msclickhouse_brew520 msFirebolt886 msDataFusion705 msClickHouse622 ms
  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: Landfall Freight & Lowlands Express performance by destination country, full year 2025
      Question: Are our two chronically weak carriers bad everywhere, or concentrated on specific lanes/countries?
      Grain: one row per carrier and destination country (Landfall Freight and Lowlands Express only), full year 2025
      Columns:
      - carrier
      - destination_country
      - shipments_shipped
      - avg_transit_days
      - pct_within_3_days
      - share_of_carrier_shipments_pct (this country's shipments / that carrier's total 2025 shipments, x100)
      Details: Tables: shipments (carrier in ('Landfall Freight','Lowlands Express'), shipped_at between 2025-01-01 and 2025-12-31, delivered_at) joined via fulfillments -> orders -> addresses (shipping_address_id) -> countries. transit_days = DATEDIFF(day, shipped_at, delivered_at), delivered subset only. Round avg_transit_days to 2 decimals, pct columns to 1 decimal. Include only countries with at least 15 shipments for that carrier in the year. Order by carrier ascending, then shipments_shipped descending.
      
      Check your query with the warehouse's dry_run tool, then hand it in with submit.
    • Omar calls dry_run
      WITH base AS (
        SELECT
          s.carrier,
          co.name AS destination_country,
          s.id AS shipment_id,
          s.delivered_at,
          (CAST(s.delivered_at AS date) - CAST(s.shipped_at AS date)) AS transit_days
        FROM shipments s
        JOIN fulfillments f ON f.id = s.fulfillment_id
        JOIN orders o ON o.id = f.order_id
        JOIN addresses a ON a.id = o.shipping_address_id
        JOIN countries co ON co.id = a.country_id
        WHERE s.carrier IN ('Landfall Freight','Lowlands Express')
          AND s.shipped_at >= TIMESTAMP '2025-01-01'
          AND s.shipped_at < TIMESTAMP '2026-01-01'
      ),
      carrier_totals AS (
        SELECT carrier, COUNT(*) AS carrier_shipments
        FROM base
        GROUP BY carrier
      ),
      country_stats AS (
        SELECT
          carrier,
          destination_country,
          COUNT(*) AS shipments_shipped,
          AVG(transit_days) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days,
          COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND transit_days <= 3) AS within_3_count
        FROM base
        GROUP BY carrier, destination_country
      )
      SELECT
        cs.carrier,
        cs.destination_country,
        cs.shipments_shipped,
        ROUND(cs.avg_transit_days, 2) AS avg_transit_days,
        ROUND(100.0 * cs.within_3_count / cs.shipments_shipped, 1) AS pct_within_3_days,
        ROUND(100.0 * cs.shipments_shipped / ct.carrier_shipments, 1) AS share_of_carrier_shipments_pct
      FROM country_stats cs
      JOIN carrier_totals ct ON ct.carrier = cs.carrier
      WHERE cs.shipments_shipped >= 15
      ORDER BY cs.carrier ASC, cs.shipments_shipped DESC, cs.destination_country ASC
    • The warehouse answers
      STATUS: COMPILES (dry run on the empty schema, no data read)
      COLUMNS: carrier, destination_country, shipments_shipped, avg_transit_days, pct_within_3_days, share_of_carrier_shipments_pct
    • OmarQuery compiles and returns the expected columns. Submitting.
    • Omar calls submit
      WITH base AS (
        SELECT
          s.carrier,
          co.name AS destination_country,
          s.id AS shipment_id,
          s.delivered_at,
          (CAST(s.delivered_at AS date) - CAST(s.shipped_at AS date)) AS transit_days
        FROM shipments s
        JOIN fulfillments f ON f.id = s.fulfillment_id
        JOIN orders o ON o.id = f.order_id
        JOIN addresses a ON a.id = o.shipping_address_id
        JOIN countries co ON co.id = a.country_id
        WHERE s.carrier IN ('Landfall Freight','Lowlands Express')
          AND s.shipped_at >= TIMESTAMP '2025-01-01'
          AND s.shipped_at < TIMESTAMP '2026-01-01'
      ),
      carrier_totals AS (
        SELECT carrier, COUNT(*) AS carrier_shipments
        FROM base
        GROUP BY carrier
      ),
      country_stats AS (
        SELECT
          carrier,
          destination_country,
          COUNT(*) AS shipments_shipped,
          AVG(transit_days) FILTER (WHERE delivered_at IS NOT NULL) AS avg_transit_days,
          COUNT(*) FILTER (WHERE delivered_at IS NOT NULL AND transit_days <= 3) AS within_3_count
        FROM base
        GROUP BY carrier, destination_country
      )
      SELECT
        cs.carrier,
        cs.destination_country,
        cs.shipments_shipped,
        ROUND(cs.avg_transit_days, 2) AS avg_transit_days,
        ROUND(100.0 * cs.within_3_count / cs.shipments_shipped, 1) AS pct_within_3_days,
        ROUND(100.0 * cs.shipments_shipped / ct.carrier_shipments, 1) AS share_of_carrier_shipments_pct
      FROM country_stats cs
      JOIN carrier_totals ct ON ct.carrier = cs.carrier
      WHERE cs.shipments_shipped >= 15
      ORDER BY cs.carrier ASC, cs.shipments_shipped DESC, cs.destination_country ASC
    • The warehouse answers
      Submitted to tonight's batch. Your work on this request is done.
    • OmarSubmitted. Summary of choices made where the request left room for interpretation: - **avg_transit_days**: averaged only over delivered shipments (as specified, since transit_days requires a delivery date). - **pct_within_3_days**: numerator is delivered shipments with transit_days ≤ 3, denominator is `shipments_shipped` (total shipped in that carrier/country) — so undelivered shipments count against the on-time rate rather than being excluded. - **share_of_carrier_shipments_pct**: denominator is each carrier's full 2025 shipment count across *all* destination countries, not just the countries that cleared the 15-shipment reporting threshold — so the shares reflect true concentration even if they don't sum to 100% across the printed rows. These are noted in the submit note for Lena.