DB Olympics

Queries · q083 · VP Product · week 1, night 3

Cart abandonment timing by tenant, Q4 2025 (retail merchants)

“Is the 'slow bleed' pattern in cart abandonment (most unresolved carts linger 1 hour to 7 days rather than dying instantly) consistent across retail merchants, or is it driven by one or two tenants' cart-expiry settings?”

Manager · asked the questionJonas FeldVP Product. Joined from a mobile-first retailer. Deciding the 2026 roadmap.
Analyst · planned the reportEmeka ObiCustomer-centric: follows cohorts of shoppers or merchants over time.
Engineer · wrote the SQLViktorOld-school warehouse engineer: explicit JOIN chains straight to the base tables, derived tables, GROUP BY with CASE pivots, few CTEs.

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

  1. A business event lands on the VP Product's desk

    Week 1

    We are redesigning the shopper journey for 2026. We need to understand the whole path, from the first visit to checkout, delivery, returns and the next purchase, and where shoppers drop out and why.

  2. Jonas Feld writes to Emeka Obi

    The manager, at the start of week 1

    Subject: Shopper journey end-to-end — what I need for the 2026 roadmap

    Emeka,

    We're resetting the shopper journey for 2026, and I need a clear picture of the whole path — first visit through checkout, delivery, returns, and whether people come back — so we can decide where to invest design and engineering time first. This feeds the roadmap review I'm presenting in two weeks, so the Friday memo should leave me able to say "here's where shoppers are leaking out, and here's the one or two places a fix would move the most volume."

    I know you only get a handful of report slots this week, so please prioritize in the order below — stop earlier in the list if something forces a tradeoff, rather than spreading thin across all of it.

    1. Where do we lose people between landing on the storefront and placing an order? I want to see the shape of the funnel (visit → browse/search → cart → checkout → paid order) and which step is the biggest drop-off, ideally for a few of our bigger merchants so we're not averaging away real differences.
    2. Once someone reaches checkout, what's stopping them from finishing? Is it a one-step cliff or a slow bleed across the checkout flow, and does it differ by device or by how they arrived (e.g. ad vs. direct vs. returning)?
    3. After the order is placed, how is delivery experience affecting trust? I want to understand how often deliveries run late and whether that visibly connects to returns or to people not coming back.
    4. How painful are returns, and does a return kill the relationship? I'd like a sense of how often a return leads to the shopper buying again within a reasonable window versus going quiet.
    5. Who comes back, and how soon? A simple read on repeat purchase behavior — how many first-time buyers return, and roughly how long it takes — would help me know if we're building a roadmap for acquisition or for retention.

    If you can only land three of these this week, do 1, 2 and 5 — funnel, checkout, and repeat purchase are the ones I most need going into the roadmap conversation. Delivery and returns can follow next week if we run out of nights.

    Thanks — looking forward to Friday.

    Jonas

  3. Emeka Obi plans the night

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

    Reading night 2 critically:

    Report 1 (tracking coverage) confirms the Report-1/night-1 puzzle, but not quite the way I expected: the four Food & Coffee merchants have visits_per_order well under 1 (0.53-0.73) — far more orders than visits — while the retail merchants (Pet Supplies, Beauty, Apparel, Electronics) sit at a believable 1.0-3.3 visits per order. BUT subscription_linked_orders_pct is 0.0% everywhere, so the orders aren't literally tied to subscription invoices via orders.id — meaning subscription billing in this schema doesn't create a browsing/checkout event at all, it just produces order rows directly (automated renewal), with zero session footprint. That's the real explanation: for subscription merchants, "order" ≠ "someone browsed and checked out," so the storefront funnel simply doesn't apply to most of their volume. I'll segment subscription vs. retail merchants in the memo and scope the "where do we leak" funnel conclusion to the retail segment, where the numbers are coherent.

    Report 2 (status-transition funnel) has a methodology problem I caused: I told the engineer "same 10 tenants as the Q4 funnel report" without giving the explicit list, so they substituted a top-order-count proxy — which is almost certainly dominated by the high-volume subscription merchants (confirmed status never appears, pending→paid is ~98% instant at 0.0 median hours, consistent with automated billing that has no checkout UI to abandon). This result doesn't answer the retail checkout question I actually need — I have to rerun it with the explicit 6 retail tenant_ids.

    Report 3 (cart duration) is clean and tenant-matched correctly, and it's a real finding: only 29% of carts resolve within an hour (and those are ~100% converted — fast successful checkouts, not failures); the bulk, 67.7% combined, linger 1 hour to 7 days before mostly failing (1.8%-15.3% conversion). That's a genuine slow bleed, not a single cliff. I want to check this isn't an artifact of one tenant's cart-expiry policy before I put it in the memo as a general pattern.

    Tonight (night 3 of 4): fix the contaminated status-transition report with the explicit retail tenant list, check whether the cart-bleed pattern holds per-tenant or is driven by an outlier, and — since priorities 1/2/5 are now in good shape — spend the third slot starting priority 3 (delivery lateness vs. returns) so there's something to work with next week even if we run out of nights.

    Cart abandonment timing by tenant, Q4 2025 (retail merchants)
    Question
    Is the 'slow bleed' pattern in cart abandonment (most unresolved carts linger 1 hour to 7 days rather than dying instantly) consistent across retail merchants, or is it driven by one or two tenants' cart-expiry settings?
    One row per
    tenant and duration bucket
    Columns
    • tenant name
    • duration bucket
    • cart count
    • pct of that tenant's carts
    • converted pct (share of carts in this bucket with status = converted)
  4. Viktor 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)
    SELECT
        t.name AS tenant_name,
        b.bucket,
        COUNT(*) AS cart_count,
        ROUND(100.0 * COUNT(*) / SUM(COUNT(*)) OVER (PARTITION BY t.name), 1) AS pct_of_tenant_carts,
        ROUND(100.0 * SUM(CASE WHEN b.status = 'converted' THEN 1 ELSE 0 END) / COUNT(*), 1) AS converted_pct
    FROM (
        SELECT
            c.tenant_id,
            c.status,
            CASE
                WHEN c.converted_at IS NULL AND c.abandoned_at IS NULL AND c.expires_at IS NULL
                    THEN 'unresolved/still active'
                WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 1
                    THEN '<1 hour'
                WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 24
                    THEN '1-24 hours'
                WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 168
                    THEN '1-7 days'
                ELSE '>7 days'
            END AS bucket
        FROM carts c
        WHERE c.created_at >= DATE '2025-10-01' AND c.created_at < DATE '2026-01-01'
    ) b
    JOIN tenants t ON t.id = b.tenant_id
    WHERE t.name IN ('Kibblewick', 'Studio Vrij', 'Petalcourt Beauty', 'Marrowby & Vane', 'Cragsley Outfitters', 'Ampfeld Elektronik')
    GROUP BY t.name, b.bucket
    ORDER BY t.name,
        CASE b.bucket
            WHEN '<1 hour' THEN 1
            WHEN '1-24 hours' THEN 2
            WHEN '1-7 days' THEN 3
            WHEN '>7 days' THEN 4
            WHEN 'unresolved/still active' THEN 5
        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 tenant/bucket (≤30 rows total across the 6 named retail merchants), with cart counts, each bucket's share of that tenant's Q4 carts, and the converted-status share per cell — letting the analyst see at a glance whether the slow-bleed pattern (concentration in 1–24h and 1–7 day buckets) holds across all six tenants or is dominated by one or two.”

  5. The report comes back overnight

    As Emeka Obi saw it, from the small dataset the agents worked on

    tenant_name         | bucket     | cart_count | pct_of_tenant_carts | converted_pct
    --------------------+------------+------------+---------------------+--------------
    Ampfeld Elektronik  | <1 hour    |        163 |                22.6 |         100.0
    Ampfeld Elektronik  | 1-24 hours |        248 |                34.4 |           0.8
    Ampfeld Elektronik  | 1-7 days   |        286 |                39.7 |           9.8
    Ampfeld Elektronik  | >7 days    |         23 |                 3.2 |           4.3
    Cragsley Outfitters | <1 hour    |       1150 |                29.3 |         100.0
    Cragsley Outfitters | 1-24 hours |       1150 |                29.3 |           1.5
    Cragsley Outfitters | 1-7 days   |       1475 |                37.6 |          16.4
    Cragsley Outfitters | >7 days    |        147 |                 3.7 |          19.0
    Kibblewick          | <1 hour    |         87 |                26.4 |         100.0
    Kibblewick          | 1-24 hours |        100 |                30.3 |           4.0
    Kibblewick          | 1-7 days   |        134 |                40.6 |          14.9
    Kibblewick          | >7 days    |          9 |                 2.7 |          22.2
    Marrowby & Vane     | <1 hour    |        545 |                30.0 |         100.0
    Marrowby & Vane     | 1-24 hours |        525 |                28.9 |           2.9
    Marrowby & Vane     | 1-7 days   |        697 |                38.3 |          13.8
    Marrowby & Vane     | >7 days    |         51 |                 2.8 |           7.8
    Petalcourt Beauty   | <1 hour    |        211 |                31.5 |         100.0
    Petalcourt Beauty   | 1-24 hours |        225 |                33.6 |           0.9
    Petalcourt Beauty   | 1-7 days   |        215 |                32.1 |          18.6
    Petalcourt Beauty   | >7 days    |         18 |                 2.7 |          16.7
    Studio Vrij         | <1 hour    |        194 |                29.8 |         100.0
    Studio Vrij         | 1-24 hours |        207 |                31.8 |           2.4
    Studio Vrij         | 1-7 days   |        227 |                34.9 |          16.3
    Studio Vrij         | >7 days    |         23 |                 3.5 |          17.4
    (24 rows)
  6. 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:

  7. It becomes benchmark query q083

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

    • numericsdocs/NUMERICS.md: rounding removed; results keep full precision
    • numericsdocs/NUMERICS.md: EXTRACT(EPOCH FROM (b - a)) cast to NUMERIC(18,6) (3×)
    • made explicita selected t.col gets AS col, its standard name made explicit (3×)
    • placeholderseconds between (3×)
    • determinismthe standard leaves the place of NULLs in a sort to the implementation: NULLS LAST ascending, NULLS FIRST descending, as in the reference results (2×)
    The benchmark text, against the submitted SQL
    SELECT    t.name AS tenant_name,    b.bucket,    b.bucket AS bucket,    COUNT(*) AS cart_count,    ROUND(100.0 * COUNT(*) / SUM(COUNT(*)) OVER (PARTITION BY t.name), 1) AS pct_of_tenant_carts,    ROUND(100.0 * SUM(CASE WHEN b.status = 'converted' THEN 1 ELSE 0 END) / COUNT(*), 1) AS converted_pct    100.0 * COUNT(*) / SUM(COUNT(*)) OVER (PARTITION BY t.name) AS pct_of_tenant_carts,    100.0 * SUM(CASE WHEN b.status = 'converted' THEN 1 ELSE 0 END) / COUNT(*) AS converted_pctFROM (    SELECT        c.tenant_id,        c.status,        c.tenant_id AS tenant_id,        c.status AS status,        CASE            WHEN c.converted_at IS NULL AND c.abandoned_at IS NULL AND c.expires_at IS NULL                THEN 'unresolved/still active'            WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 1            WHEN {{seconds_between(c.created_at, COALESCE(c.converted_at, c.abandoned_at, c.expires_at))}} / 3600.0 < 1                THEN '<1 hour'            WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 24            WHEN {{seconds_between(c.created_at, COALESCE(c.converted_at, c.abandoned_at, c.expires_at))}} / 3600.0 < 24                THEN '1-24 hours'            WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 168            WHEN {{seconds_between(c.created_at, COALESCE(c.converted_at, c.abandoned_at, c.expires_at))}} / 3600.0 < 168                THEN '1-7 days'            ELSE '>7 days'        END AS bucket    FROM carts c    WHERE c.created_at >= DATE '2025-10-01' AND c.created_at < DATE '2026-01-01') bJOIN tenants t ON t.id = b.tenant_idWHERE t.name IN ('Kibblewick', 'Studio Vrij', 'Petalcourt Beauty', 'Marrowby & Vane', 'Cragsley Outfitters', 'Ampfeld Elektronik')GROUP BY t.name, b.bucketORDER BY t.name,ORDER BY t.name NULLS LAST,    CASE b.bucket        WHEN '<1 hour' THEN 1        WHEN '1-24 hours' THEN 2        WHEN '1-7 days' THEN 3        WHEN '>7 days' THEN 4        WHEN 'unresolved/still active' THEN 5    END    END NULLS LAST
    SELECT
        t.name AS tenant_name,
        b.bucket AS bucket,
        COUNT(*) AS cart_count,
        100.0 * COUNT(*) / SUM(COUNT(*)) OVER (PARTITION BY t.name) AS pct_of_tenant_carts,
        100.0 * SUM(CASE WHEN b.status = 'converted' THEN 1 ELSE 0 END) / COUNT(*) AS converted_pct
    FROM (
        SELECT
            c.tenant_id AS tenant_id,
            c.status AS status,
            CASE
                WHEN c.converted_at IS NULL AND c.abandoned_at IS NULL AND c.expires_at IS NULL
                    THEN 'unresolved/still active'
                WHEN CAST(EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) AS NUMERIC(18,6)) / 3600.0 < 1
                    THEN '<1 hour'
                WHEN CAST(EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) AS NUMERIC(18,6)) / 3600.0 < 24
                    THEN '1-24 hours'
                WHEN CAST(EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) AS NUMERIC(18,6)) / 3600.0 < 168
                    THEN '1-7 days'
                ELSE '>7 days'
            END AS bucket
        FROM carts c
        WHERE c.created_at >= DATE '2025-10-01' AND c.created_at < DATE '2026-01-01'
    ) b
    JOIN tenants t ON t.id = b.tenant_id
    WHERE t.name IN ('Kibblewick', 'Studio Vrij', 'Petalcourt Beauty', 'Marrowby & Vane', 'Cragsley Outfitters', 'Ampfeld Elektronik')
    GROUP BY t.name, b.bucket
    ORDER BY t.name NULLS LAST,
        CASE b.bucket
            WHEN '<1 hour' THEN 1
            WHEN '1-24 hours' THEN 2
            WHEN '1-7 days' THEN 3
            WHEN '>7 days' THEN 4
            WHEN 'unresolved/still active' THEN 5
        END NULLS LAST
    10 ms100 ms1 sHyper13.0 msDuckDB59.6 msGizmoSQL45.8 msclickhouse_brew131 msFirebolt87.5 msDataFusion249 msClickHouse727 ms
  8. 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

    Viktor's whole session, 7 turns
    • The request, as Viktor received it
      Report request from Emeka Obi (analyst for the VP Product):
      
      Title: Cart abandonment timing by tenant, Q4 2025 (retail merchants)
      Question: Is the 'slow bleed' pattern in cart abandonment (most unresolved carts linger 1 hour to 7 days rather than dying instantly) consistent across retail merchants, or is it driven by one or two tenants' cart-expiry settings?
      Grain: one row per tenant and duration bucket
      Columns:
      - tenant name
      - duration bucket
      - cart count
      - pct of that tenant's carts
      - converted pct (share of carts in this bucket with status = converted)
      Details: Same tenant list, time window, and bucket definitions as the earlier 'Cart abandonment: cliff or slow bleed' report: carts with created_at in 2025-10-01 to 2025-12-31 for Kibblewick, Studio Vrij, Petalcourt Beauty, Marrowby & Vane, Cragsley Outfitters, Ampfeld Elektronik. resolution_time = coalesce(converted_at, abandoned_at, expires_at) - created_at in hours; carts with all three null go in 'unresolved/still active'. Buckets: '<1 hour', '1-24 hours', '1-7 days', '>7 days', 'unresolved/still active'. pct_of_tenant_carts is computed within each tenant (so the 5 buckets sum to ~100% per tenant), not across the whole population. converted_pct = % of carts in that tenant/bucket cell with status = 'converted', rounded 1 decimal. Order rows by tenant_name, then bucket in the fixed sequence above (not alphabetical).
      
      Check your query with the warehouse's dry_run tool, then hand it in with submit.
    • Viktor calls dry_run
      SELECT
          t.name AS tenant_name,
          b.bucket,
          COUNT(*) AS cart_count,
          ROUND(100.0 * COUNT(*) / SUM(COUNT(*)) OVER (PARTITION BY t.name), 1) AS pct_of_tenant_carts,
          ROUND(100.0 * SUM(CASE WHEN b.status = 'converted' THEN 1 ELSE 0 END) / COUNT(*), 1) AS converted_pct
      FROM (
          SELECT
              c.tenant_id,
              c.status,
              CASE
                  WHEN c.converted_at IS NULL AND c.abandoned_at IS NULL AND c.expires_at IS NULL
                      THEN 'unresolved/still active'
                  WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 1
                      THEN '<1 hour'
                  WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 24
                      THEN '1-24 hours'
                  WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 168
                      THEN '1-7 days'
                  ELSE '>7 days'
              END AS bucket
          FROM carts c
          WHERE c.created_at >= DATE '2025-10-01' AND c.created_at < DATE '2026-01-01'
      ) b
      JOIN tenants t ON t.id = b.tenant_id
      WHERE t.name IN ('Kibblewick', 'Studio Vrij', 'Petalcourt Beauty', 'Marrowby & Vane', 'Cragsley Outfitters', 'Ampfeld Elektronik')
      GROUP BY t.name, b.bucket
      ORDER BY t.name,
          CASE b.bucket
              WHEN '<1 hour' THEN 1
              WHEN '1-24 hours' THEN 2
              WHEN '1-7 days' THEN 3
              WHEN '>7 days' THEN 4
              WHEN 'unresolved/still active' THEN 5
          END
    • The warehouse answers
      STATUS: COMPILES (dry run on the empty schema, no data read)
      COLUMNS: tenant_name, bucket, cart_count, pct_of_tenant_carts, converted_pct
    • ViktorQuery compiles and returns the expected columns. Submitting.
    • Viktor calls submit
      SELECT
          t.name AS tenant_name,
          b.bucket,
          COUNT(*) AS cart_count,
          ROUND(100.0 * COUNT(*) / SUM(COUNT(*)) OVER (PARTITION BY t.name), 1) AS pct_of_tenant_carts,
          ROUND(100.0 * SUM(CASE WHEN b.status = 'converted' THEN 1 ELSE 0 END) / COUNT(*), 1) AS converted_pct
      FROM (
          SELECT
              c.tenant_id,
              c.status,
              CASE
                  WHEN c.converted_at IS NULL AND c.abandoned_at IS NULL AND c.expires_at IS NULL
                      THEN 'unresolved/still active'
                  WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 1
                      THEN '<1 hour'
                  WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 24
                      THEN '1-24 hours'
                  WHEN EXTRACT(EPOCH FROM (COALESCE(c.converted_at, c.abandoned_at, c.expires_at) - c.created_at)) / 3600.0 < 168
                      THEN '1-7 days'
                  ELSE '>7 days'
              END AS bucket
          FROM carts c
          WHERE c.created_at >= DATE '2025-10-01' AND c.created_at < DATE '2026-01-01'
      ) b
      JOIN tenants t ON t.id = b.tenant_id
      WHERE t.name IN ('Kibblewick', 'Studio Vrij', 'Petalcourt Beauty', 'Marrowby & Vane', 'Cragsley Outfitters', 'Ampfeld Elektronik')
      GROUP BY t.name, b.bucket
      ORDER BY t.name,
          CASE b.bucket
              WHEN '<1 hour' THEN 1
              WHEN '1-24 hours' THEN 2
              WHEN '1-7 days' THEN 3
              WHEN '>7 days' THEN 4
              WHEN 'unresolved/still active' THEN 5
          END
    • The warehouse answers
      Submitted to tonight's batch. Your work on this request is done.
    • ViktorSubmitted. The report gives one row per tenant/bucket (≤30 rows total across the 6 named retail merchants), with cart counts, each bucket's share of that tenant's Q4 carts, and the converted-status share per cell — letting the analyst see at a glance whether the slow-bleed pattern (concentration in 1–24h and 1–7 day buckets) holds across all six tenants or is dominated by one or two.