DB Olympics

Queries · q353 · Head of Merchandising · week 2, night 3

Wiesgrund Wohnen December 2025: Product-Level Review Breakdown

“Since delivery performance doesn't explain Wiesgrund Wohnen's December dip, which specific products drove it?”

Manager · asked the questionFreya LindgrenHead of Merchandising. Came from a fashion marketplace's catalog team. Responsible for helping merchants present their products well.
Analyst · planned the reportZara AhmedExploratory: looks at the raw detail of an unfamiliar area before aggregating it.
Engineer · wrote the SQLFelixJunior engineer who nests subqueries in FROM and WHERE (IN, EXISTS, correlated subqueries) rather than CTEs.

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

  1. Freya Lindgren writes to Zara Ahmed

    The manager, at the start of week 2

    Subject: Good start — let's dig into the risk areas

    Hi Zara,

    This is really useful, and a few things jumped out that I want to understand better before Friday.

    The Cragsley Outfitters finding worries me most — our #2 merchant by revenue with real quality concentration, and some of those poorly-rated items are still selling briskly. That combination (strong sales, weak ratings, sizable product count) feels like the kind of thing that erodes trust quietly until it doesn't. I'd like to understand it better: is this concentrated in certain kinds of products, has it been building over time, and does it look like it's about to hit sales or is demand just lagging behind reputation?

    Second, the December rating dip needs a clearer story. You flagged it as needing a second month to confirm — I agree, but I'd also like to understand whether there's something explainable behind it (seasonal returns, a particular product push, shipping delays around the holidays) rather than just watching and waiting. If Fennel & Flint and Wiesgrund Wohnen are worth a check-in, I want to go into that conversation knowing roughly what happened.

    Third, I was surprised that going from zero to one image makes such a big difference but more images after that don't. Before I turn that into a merchant talking point, I want to know if we're actually looking at a real presentation effect or just a stand-in for something else — are the zero-image listings systematically different in some way, like older, or a different kind of product?

    Finally, on bundles: you said it's white space but we can't test performance yet because usage is too rare. I'd like to understand it a bit more anecdotally before we design a pilot — among the handful of merchants that do use bundles, is there anything that distinguishes them, even descriptively, from the ones that don't?

    Thanks again — this is exactly the kind of clarity I needed.

    Freya

  2. Zara Ahmed plans the night

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

    Night 2 findings: (1) The shipping-delay hypothesis for the Dec dip holds for Fennel & Flint with a plausible lag — their on-time delivery crashed to 53.7% in November (from ~85-88% normally) and their bad reviews peaked the following month, December (14 reviews, 3.14 avg, 35.7% 1-2 star). But it does NOT explain Wiesgrund Wohnen at all: their delivery performance stayed strong all through Nov-Dec (90.9%, 93.8%) and they used 0% Albion Parcel every single month — yet they had an equally bad December (12 reviews, 3.5 avg, 41.7% 1-2 star). So there are two different causes behind what looked like one 'Home & Living dip,' and I need to find Wiesgrund Wohnen's actual driver. (2) The image-bucket report, run without the active-only filter this time, overturned my 'maybe they're just new/unfinished listings' theory: the 85 zero-image products are actually the OLDEST on average (1,136 days vs ~1,040 for others) and have fewer variants (3.4 vs ~5.5) — these are neglected legacy active listings, not pending-content new ones, and notably zero B2B merchants have any zero-image products (B2B is always at least minimally photographed). So the zero-to-one-image effect looks like a real, if small and old, content gap worth cleaning up, not a proxy for recency. (3) The bundle-user list makes the pattern obvious just from eyeballing the 50 rows: every single bundle-using merchant is in Beauty, Food & Coffee, Books & Stationery, Jewelry, Consumer Electronics, or Home & Living — none are Apparel & Footwear, Sports & Outdoor, or B2B wholesale, and they skew toward low-variant, giftable, small-revenue merchants. I want one clean aggregate to confirm this is a true vertical pattern and not an artifact of which merchants happened to print. Tonight: drill into Wiesgrund Wohnen's actual December driver at the product level, check whether both merchants' December dips are a recurring yearly pattern (like Cragsley's) or unique to 2025, and confirm the bundle-vertical clustering with hard numbers.

    Wiesgrund Wohnen December 2025: Product-Level Review Breakdown
    Question
    Since delivery performance doesn't explain Wiesgrund Wohnen's December dip, which specific products drove it?
    One row per
    product, for Wiesgrund Wohnen only, among products with at least one approved review created in December 2025
    Columns
    • product_name
    • category_name
    • review_count
    • avg_rating
    • pct_1_2_star
    • units_sold_last_12mo
  3. Felix 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 p.name as product_name,
           c.name as category_name,
           r.review_count,
           r.avg_rating,
           r.pct_1_2_star,
           (SELECT COALESCE(SUM(oi.quantity),0)
            FROM order_items oi
            JOIN orders o ON o.id = oi.order_id
            WHERE o.tenant_id = p.tenant_id
              AND o.status <> 'cancelled'
              AND o.placed_at >= timestamp '2025-01-01' AND o.placed_at < timestamp '2026-01-01'
              AND oi.product_variant_id IN (SELECT pv.id FROM product_variants pv WHERE pv.product_id = p.id)
           ) AS units_sold_last_12mo
    FROM products p
    JOIN categories c ON c.id = p.primary_category_id
    JOIN (
       SELECT pr.product_id,
              COUNT(*) AS review_count,
              ROUND(AVG(pr.rating),2) AS avg_rating,
              ROUND(100.0 * SUM(CASE WHEN pr.rating IN (1,2) THEN 1 ELSE 0 END) / COUNT(*), 1) AS pct_1_2_star
       FROM product_reviews pr
       WHERE pr.is_approved = true
         AND pr.created_at >= timestamp '2025-12-01' AND pr.created_at < timestamp '2026-01-01'
         AND pr.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')
       GROUP BY pr.product_id
    ) r ON r.product_id = p.id
    WHERE p.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')
    ORDER BY r.review_count DESC, r.avg_rating ASC, p.name 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. The report returns one row per Wiesgrund Wohnen product with at least one approved December 2025 review, showing review volume/rating stats alongside trailing-12-month unit sales for context, ordered by review count (desc) then average rating (asc).”

  4. The report comes back overnight

    As Zara Ahmed saw it, from the small dataset the agents worked on

    product_name                        | category_name | review_count | avg_rating | pct_1_2_star | units_sold_last_12mo
    ------------------------------------+---------------+--------------+------------+--------------+---------------------
    Stainless 24cm Frying Pan           | Cookware      |            2 |        4.0 |          0.0 |                    7
    20cm Chef's Knife                   | Cookware      |            2 |        5.0 |          0.0 |                   26
    Fluted Stoneware Vase               | Decor         |            1 |        1.0 |        100.0 |                   12
    Carbon Steel 26cm Frying Pan        | Cookware      |            1 |        2.0 |        100.0 |                    2
    Fluted Ceramic Vase                 | Decor         |            1 |        2.0 |        100.0 |                    1
    Set of 4 Stoneware Dinner Plate Set | Tableware     |            1 |        2.0 |        100.0 |                   11
    Shallow 28cm Casserole Dish         | Cookware      |            1 |        2.0 |        100.0 |                   18
    Bud Recycled Glass Vase             | Decor         |            1 |        5.0 |          0.0 |                    5
    Plush Bath Towel                    | Towels        |            1 |        5.0 |          0.0 |                   24
    Tumblers Set of 4 Glassware Set     | Glassware     |            1 |        5.0 |          0.0 |                   20
    (10 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 q353

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

    • determinismtie-breaker: product names are not unique
    • numericsdocs/NUMERICS.md: rounding removed; results keep full precision; AVG over an integer computed as a decimal: AVG(CAST(x AS NUMERIC(18,6)))
    • made explicita selected t.col gets AS col, its standard name made explicit (4×)
    • determinismthe standard leaves the place of NULLs in a sort to the implementation: NULLS LAST ascending, NULLS FIRST descending, as in the reference results (4×)
    The benchmark text, against the submitted SQL
    SELECT p.name as product_name,       c.name as category_name,       r.review_count,       r.avg_rating,       r.pct_1_2_star,       r.review_count AS review_count,       r.avg_rating AS avg_rating,       r.pct_1_2_star AS pct_1_2_star,       (SELECT COALESCE(SUM(oi.quantity),0)        FROM order_items oi        JOIN orders o ON o.id = oi.order_id        WHERE o.tenant_id = p.tenant_id          AND o.status <> 'cancelled'          AND o.placed_at >= timestamp '2025-01-01' AND o.placed_at < timestamp '2026-01-01'          AND oi.product_variant_id IN (SELECT pv.id FROM product_variants pv WHERE pv.product_id = p.id)       ) AS units_sold_last_12moFROM products pJOIN categories c ON c.id = p.primary_category_idJOIN (   SELECT pr.product_id,   SELECT pr.product_id AS product_id,          COUNT(*) AS review_count,          ROUND(AVG(pr.rating),2) AS avg_rating,          ROUND(100.0 * SUM(CASE WHEN pr.rating IN (1,2) THEN 1 ELSE 0 END) / COUNT(*), 1) AS pct_1_2_star          AVG(CAST(pr.rating AS NUMERIC(18,6))) AS avg_rating,          100.0 * SUM(CASE WHEN pr.rating IN (1,2) THEN 1 ELSE 0 END) / COUNT(*) AS pct_1_2_star   FROM product_reviews pr   WHERE pr.is_approved = true     AND pr.created_at >= timestamp '2025-12-01' AND pr.created_at < timestamp '2026-01-01'     AND pr.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')   GROUP BY pr.product_id) r ON r.product_id = p.idWHERE p.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')ORDER BY r.review_count DESC, r.avg_rating ASC, p.name ASCORDER BY r.review_count DESC NULLS FIRST, r.avg_rating ASC NULLS LAST, p.name ASC NULLS LAST, p.id ASC NULLS LAST
    SELECT p.name as product_name,
           c.name as category_name,
           r.review_count AS review_count,
           r.avg_rating AS avg_rating,
           r.pct_1_2_star AS pct_1_2_star,
           (SELECT COALESCE(SUM(oi.quantity),0)
            FROM order_items oi
            JOIN orders o ON o.id = oi.order_id
            WHERE o.tenant_id = p.tenant_id
              AND o.status <> 'cancelled'
              AND o.placed_at >= timestamp '2025-01-01' AND o.placed_at < timestamp '2026-01-01'
              AND oi.product_variant_id IN (SELECT pv.id FROM product_variants pv WHERE pv.product_id = p.id)
           ) AS units_sold_last_12mo
    FROM products p
    JOIN categories c ON c.id = p.primary_category_id
    JOIN (
       SELECT pr.product_id AS product_id,
              COUNT(*) AS review_count,
              AVG(CAST(pr.rating AS NUMERIC(18,6))) AS avg_rating,
              100.0 * SUM(CASE WHEN pr.rating IN (1,2) THEN 1 ELSE 0 END) / COUNT(*) AS pct_1_2_star
       FROM product_reviews pr
       WHERE pr.is_approved = true
         AND pr.created_at >= timestamp '2025-12-01' AND pr.created_at < timestamp '2026-01-01'
         AND pr.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')
       GROUP BY pr.product_id
    ) r ON r.product_id = p.id
    WHERE p.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')
    ORDER BY r.review_count DESC NULLS FIRST, r.avg_rating ASC NULLS LAST, p.name ASC NULLS LAST, p.id ASC NULLS LAST
    100 ms1 s10 sHyper1.01 sDuckDB5.58 sGizmoSQL4.47 sclickhouse_brew268 msFirebolt388 msDataFusionerrorClickHouseerror
    • DataFusionSchema error: No field named p.id.
    • ClickHouseCode: 48. DB::Exception: Correlated subqueries are not supported as IN function arguments yet, but found in expression: oi.product_variant_id IN (SELECT pv.id FROM product_variants AS pv WHERE pv.product_id = p.id). (NOT_IMPLEMENTED)
  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

    Felix's whole session, 7 turns
    • The request, as Felix received it
      Report request from Zara Ahmed (analyst for the Head of Merchandising):
      
      Title: Wiesgrund Wohnen December 2025: Product-Level Review Breakdown
      Question: Since delivery performance doesn't explain Wiesgrund Wohnen's December dip, which specific products drove it?
      Grain: one row per product, for Wiesgrund Wohnen only, among products with at least one approved review created in December 2025
      Columns:
      - product_name
      - category_name
      - review_count
      - avg_rating
      - pct_1_2_star
      - units_sold_last_12mo
      Details: Filter to tenant = Wiesgrund Wohnen. review_count/avg_rating/pct_1_2_star computed over approved product_reviews with created_at between 2025-12-01 and 2025-12-31, per product. category_name from products.primary_category_id -> categories.name. units_sold_last_12mo = sum of order_items.quantity for that product's variants from orders placed 2025-01-01 to 2025-12-31 with status not cancelled, for context on whether it's a popular or niche item. Round avg_rating to 2 decimals, pct to 1 decimal. Order by review_count descending, tie-break by avg_rating ascending.
      
      Check your query with the warehouse's dry_run tool, then hand it in with submit.
    • Felix calls dry_run
      SELECT p.name as product_name,
             c.name as category_name,
             r.review_count,
             r.avg_rating,
             r.pct_1_2_star,
             (SELECT COALESCE(SUM(oi.quantity),0)
              FROM order_items oi
              JOIN orders o ON o.id = oi.order_id
              WHERE o.tenant_id = p.tenant_id
                AND o.status <> 'cancelled'
                AND o.placed_at >= timestamp '2025-01-01' AND o.placed_at < timestamp '2026-01-01'
                AND oi.product_variant_id IN (SELECT pv.id FROM product_variants pv WHERE pv.product_id = p.id)
             ) AS units_sold_last_12mo
      FROM products p
      JOIN categories c ON c.id = p.primary_category_id
      JOIN (
         SELECT pr.product_id,
                COUNT(*) AS review_count,
                ROUND(AVG(pr.rating),2) AS avg_rating,
                ROUND(100.0 * SUM(CASE WHEN pr.rating IN (1,2) THEN 1 ELSE 0 END) / COUNT(*), 1) AS pct_1_2_star
         FROM product_reviews pr
         WHERE pr.is_approved = true
           AND pr.created_at >= timestamp '2025-12-01' AND pr.created_at < timestamp '2026-01-01'
           AND pr.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')
         GROUP BY pr.product_id
      ) r ON r.product_id = p.id
      WHERE p.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')
      ORDER BY r.review_count DESC, r.avg_rating ASC, p.name ASC
    • The warehouse answers
      STATUS: COMPILES (dry run on the empty schema, no data read)
      COLUMNS: product_name, category_name, review_count, avg_rating, pct_1_2_star, units_sold_last_12mo
    • FelixQuery compiles and returns the expected columns. Submitting.
    • Felix calls submit
      SELECT p.name as product_name,
             c.name as category_name,
             r.review_count,
             r.avg_rating,
             r.pct_1_2_star,
             (SELECT COALESCE(SUM(oi.quantity),0)
              FROM order_items oi
              JOIN orders o ON o.id = oi.order_id
              WHERE o.tenant_id = p.tenant_id
                AND o.status <> 'cancelled'
                AND o.placed_at >= timestamp '2025-01-01' AND o.placed_at < timestamp '2026-01-01'
                AND oi.product_variant_id IN (SELECT pv.id FROM product_variants pv WHERE pv.product_id = p.id)
             ) AS units_sold_last_12mo
      FROM products p
      JOIN categories c ON c.id = p.primary_category_id
      JOIN (
         SELECT pr.product_id,
                COUNT(*) AS review_count,
                ROUND(AVG(pr.rating),2) AS avg_rating,
                ROUND(100.0 * SUM(CASE WHEN pr.rating IN (1,2) THEN 1 ELSE 0 END) / COUNT(*), 1) AS pct_1_2_star
         FROM product_reviews pr
         WHERE pr.is_approved = true
           AND pr.created_at >= timestamp '2025-12-01' AND pr.created_at < timestamp '2026-01-01'
           AND pr.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')
         GROUP BY pr.product_id
      ) r ON r.product_id = p.id
      WHERE p.tenant_id = (SELECT id FROM tenants WHERE name = 'Wiesgrund Wohnen')
      ORDER BY r.review_count DESC, r.avg_rating ASC, p.name ASC
    • The warehouse answers
      Submitted to tonight's batch. Your work on this request is done.
    • FelixSubmitted. The report returns one row per Wiesgrund Wohnen product with at least one approved December 2025 review, showing review volume/rating stats alongside trailing-12-month unit sales for context, ordered by review count (desc) then average rating (asc).