Queries · q258 · Head of Growth Marketing · week 2, night 1
“Is the euro cost of discounting (discounts given plus refunds on those orders) trending up or down over the course of 2025, in step with the refund-rate creep other teams have flagged?”
Fictional people at a fictional company, each played by a language-model agent. Who they are and what they are told
The manager, at the start of week 2
Subject: Good progress — four things I want nailed down this week
Hi Sofie,
Thanks for this — genuinely useful, and the vertical breakdown on discounting is exactly the kind of "don't trust the pooled number" catch I was worried about. A few things surprised me and I want to go deeper before I take anything to leadership.
What surprised me / needs explaining:
My questions for this week, roughly in priority order:
What I need this for: I'm trying to turn this into a short list of 2-3 concrete recommendations for merchants and for our own roadmap — where to tell them to pull back (discounting), where to double down (referrals), and where we might be quietly burning money (loyalty payouts). I'd rather have fewer, firmer answers than a wider, shakier set.
Thanks again — this is coming together well.
Chloé
The analyst · week 2, night 1, request 3 of 3
Chloé's #1 ask is a real cost picture for discounting, not just return rates, and two other teams already shipped adjacent pieces I should build on rather than duplicate: Oliver Grant (Pricing) found Welcome10's refunds now exceed its own discount cost and that no coupon has usage limits; Ingrid Solberg (Lifecycle) already did the rigorous loyalty cost-vs-value reconciliation Chloé is asking me for in Q2, including the category-mix correction on the 'members return more' claim. So tonight I'm putting all three slots behind Q1 (discounting), turning last week's return-rate finding into an actual euro cost picture by vertical, a ranked list of which specific coupon codes are worst (to give Chloé something actionable and consistent with Oliver's Welcome10 catch), and a monthly trend to see if the leakage is worsening alongside the refund-rate creep the CEO and CFO teams flagged. I'll pick up loyalty reconciliation, referral growth, and the unlinked-orders question starting night 2, leaning on Ingrid's numbers rather than re-deriving them.
The engineer · 2 dry runs on the empty schema, then the submission
WITH order_agg AS ( SELECT TO_CHAR(o.placed_at, 'YYYY-MM') AS month, COUNT(*) AS orders_count, SUM(o.discount_total * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS discount_eur, SUM(o.subtotal * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), refund_agg AS ( SELECT TO_CHAR(o.placed_at, 'YYYY-MM') AS month, SUM(ret.refund_total * CASE WHEN ret.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025 ) SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, ROUND(COALESCE(oa.discount_eur, 0), 0) AS discount_given_eur, ROUND(COALESCE(ra.refund_eur, 0), 0) AS refund_amount_eur, ROUND(COALESCE(oa.gmv_eur, 0), 0) AS gmv_eur, ROUND( CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END, 1) AS net_leakage_pct FROM months m LEFT JOIN order_agg oa ON oa.month = m.month_label LEFT JOIN refund_agg ra ON ra.month = m.month_label ORDER BY m.month_label
WITH order_agg AS ( SELECT TO_CHAR(o.placed_at, 'YYYY-MM') AS month, strftime(o.placed_at, '%Y-%m') AS month, COUNT(*) AS orders_count, SUM(o.discount_total * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS discount_eur, SUM(o.subtotal * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1),refund_agg AS ( SELECT TO_CHAR(o.placed_at, 'YYYY-MM') AS month, strftime(o.placed_at, '%Y-%m') AS month, SUM(ret.refund_total * CASE WHEN ret.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1),months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025)SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, ROUND(COALESCE(oa.discount_eur, 0), 0) AS discount_given_eur, ROUND(COALESCE(ra.refund_eur, 0), 0) AS refund_amount_eur, ROUND(COALESCE(oa.gmv_eur, 0), 0) AS gmv_eur, ROUND( CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END, 1) AS net_leakage_pctFROM months mLEFT JOIN order_agg oa ON oa.month = m.month_labelLEFT JOIN refund_agg ra ON ra.month = m.month_labelORDER BY m.month_label
“Query compiles and returns the expected columns. Submitting.”
“Submitted. The report computes, for each 2025 month: order count, EUR-converted discounts, EUR-converted refunds (attributed back to the original order's month via order_returns.order_id), GMV, and the net leakage percentage — with all 12 months guaranteed via the calendar_days dimension even if some have no qualifying orders/returns.”
As Sofie Nilsen saw it, from the small dataset the agents worked on
month | orders_count | discount_given_eur | refund_amount_eur | gmv_eur | net_leakage_pct --------+--------------+--------------------+-------------------+----------+---------------- 2025-01 | 1827 | 49786.0 | 30247.0 | 552211.0 | 14.5 2025-02 | 1400 | 25803.0 | 17427.0 | 397960.0 | 10.9 2025-03 | 1638 | 28890.0 | 22539.0 | 387778.0 | 13.3 2025-04 | 1568 | 32256.0 | 39840.0 | 446780.0 | 16.1 2025-05 | 1691 | 34930.0 | 49731.0 | 450644.0 | 18.8 2025-06 | 1509 | 24037.0 | 22741.0 | 325394.0 | 14.4 2025-07 | 1648 | 50733.0 | 21049.0 | 370784.0 | 19.4 2025-08 | 1564 | 25942.0 | 21713.0 | 334705.0 | 14.2 2025-09 | 1712 | 36184.0 | 33424.0 | 437884.0 | 15.9 2025-10 | 1879 | 34276.0 | 52837.0 | 483921.0 | 18.0 2025-11 | 2645 | 83340.0 | 78744.0 | 798013.0 | 20.3 2025-12 | 3112 | 50390.0 | 54949.0 | 658182.0 | 16.0 (12 rows)
Changed only where the benchmark needs the same result on every system
WITH order_agg AS ( SELECT strftime(o.placed_at, '%Y-%m') AS month, {{year_month(o.placed_at)}} AS month, COUNT(*) AS orders_count, SUM(o.discount_total * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS discount_eur, SUM(o.subtotal * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS gmv_eur SUM(CASE WHEN o.currency_code = 'EUR' THEN o.discount_total ELSE CAST(o.discount_total / er.rate AS NUMERIC(18,6)) END) AS discount_eur, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.subtotal ELSE CAST(o.subtotal / er.rate AS NUMERIC(18,6)) END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1),refund_agg AS ( SELECT strftime(o.placed_at, '%Y-%m') AS month, SUM(ret.refund_total * CASE WHEN ret.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS refund_eur {{year_month(o.placed_at)}} AS month, SUM(CASE WHEN ret.currency_code = 'EUR' THEN ret.refund_total ELSE CAST(ret.refund_total / er.rate AS NUMERIC(18,6)) END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1),months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025)SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, ROUND(COALESCE(oa.discount_eur, 0), 0) AS discount_given_eur, ROUND(COALESCE(ra.refund_eur, 0), 0) AS refund_amount_eur, ROUND(COALESCE(oa.gmv_eur, 0), 0) AS gmv_eur, ROUND( CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END, 1) AS net_leakage_pct COALESCE(oa.discount_eur, 0) AS discount_given_eur, COALESCE(ra.refund_eur, 0) AS refund_amount_eur, COALESCE(oa.gmv_eur, 0) AS gmv_eur, CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END AS net_leakage_pctFROM months mLEFT JOIN order_agg oa ON oa.month = m.month_labelLEFT JOIN refund_agg ra ON ra.month = m.month_labelORDER BY m.month_labelORDER BY m.month_label NULLS LAST
WITH order_agg AS ( SELECT strftime(o.placed_at, '%Y-%m') AS month, COUNT(*) AS orders_count, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.discount_total ELSE CAST(o.discount_total / er.rate AS NUMERIC(18,6)) END) AS discount_eur, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.subtotal ELSE CAST(o.subtotal / er.rate AS NUMERIC(18,6)) END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), refund_agg AS ( SELECT strftime(o.placed_at, '%Y-%m') AS month, SUM(CASE WHEN ret.currency_code = 'EUR' THEN ret.refund_total ELSE CAST(ret.refund_total / er.rate AS NUMERIC(18,6)) END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025 ) SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, COALESCE(oa.discount_eur, 0) AS discount_given_eur, COALESCE(ra.refund_eur, 0) AS refund_amount_eur, COALESCE(oa.gmv_eur, 0) AS gmv_eur, CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END AS net_leakage_pct FROM months m LEFT JOIN order_agg oa ON oa.month = m.month_label LEFT JOIN refund_agg ra ON ra.month = m.month_label ORDER BY m.month_label NULLS LAST
WITH order_agg AS ( SELECT to_char(o.placed_at, 'YYYY-MM') AS month, COUNT(*) AS orders_count, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.discount_total ELSE CAST(o.discount_total / er.rate AS NUMERIC(18,6)) END) AS discount_eur, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.subtotal ELSE CAST(o.subtotal / er.rate AS NUMERIC(18,6)) END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), refund_agg AS ( SELECT to_char(o.placed_at, 'YYYY-MM') AS month, SUM(CASE WHEN ret.currency_code = 'EUR' THEN ret.refund_total ELSE CAST(ret.refund_total / er.rate AS NUMERIC(18,6)) END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025 ) SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, COALESCE(oa.discount_eur, 0) AS discount_given_eur, COALESCE(ra.refund_eur, 0) AS refund_amount_eur, COALESCE(oa.gmv_eur, 0) AS gmv_eur, CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END AS net_leakage_pct FROM months m LEFT JOIN order_agg oa ON oa.month = m.month_label LEFT JOIN refund_agg ra ON ra.month = m.month_label ORDER BY m.month_label NULLS LAST
WITH order_agg AS ( SELECT to_char(CAST(o.placed_at AS timestamp), 'YYYY-MM') AS month, COUNT(*) AS orders_count, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.discount_total ELSE CAST(o.discount_total / er.rate AS NUMERIC(18,6)) END) AS discount_eur, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.subtotal ELSE CAST(o.subtotal / er.rate AS NUMERIC(18,6)) END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), refund_agg AS ( SELECT to_char(CAST(o.placed_at AS timestamp), 'YYYY-MM') AS month, SUM(CASE WHEN ret.currency_code = 'EUR' THEN ret.refund_total ELSE CAST(ret.refund_total / er.rate AS NUMERIC(18,6)) END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025 ) SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, COALESCE(oa.discount_eur, 0) AS discount_given_eur, COALESCE(ra.refund_eur, 0) AS refund_amount_eur, COALESCE(oa.gmv_eur, 0) AS gmv_eur, CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END AS net_leakage_pct FROM months m LEFT JOIN order_agg oa ON oa.month = m.month_label LEFT JOIN refund_agg ra ON ra.month = m.month_label ORDER BY m.month_label NULLS LAST
WITH order_agg AS ( SELECT formatDateTime(o.placed_at, '%Y-%m') AS month, COUNT(*) AS orders_count, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.discount_total ELSE CAST(o.discount_total / er.rate AS NUMERIC(18,6)) END) AS discount_eur, SUM(CASE WHEN o.currency_code = 'EUR' THEN o.subtotal ELSE CAST(o.subtotal / er.rate AS NUMERIC(18,6)) END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), refund_agg AS ( SELECT formatDateTime(o.placed_at, '%Y-%m') AS month, SUM(CASE WHEN ret.currency_code = 'EUR' THEN ret.refund_total ELSE CAST(ret.refund_total / er.rate AS NUMERIC(18,6)) END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025 ) SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, COALESCE(oa.discount_eur, 0) AS discount_given_eur, COALESCE(ra.refund_eur, 0) AS refund_amount_eur, COALESCE(oa.gmv_eur, 0) AS gmv_eur, CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END AS net_leakage_pct FROM months m LEFT JOIN order_agg oa ON oa.month = m.month_label LEFT JOIN refund_agg ra ON ra.month = m.month_label ORDER BY m.month_label NULLS LAST
The agents' own records, as the role play wrote them; only the personal data of the person who ran it is redacted
Report request from Sofie Nilsen (analyst for the Head of Growth Marketing): Title: Is discount-related revenue leakage getting worse over 2025? Question: Is the euro cost of discounting (discounts given plus refunds on those orders) trending up or down over the course of 2025, in step with the refund-rate creep other teams have flagged? Grain: one row per calendar month (2025) Columns: - month - YYYY-MM label from orders.placed_at - orders_count - count of orders placed_at in that month, all tenants - discount_given_eur - sum of orders.discount_total converted to EUR for that month's orders, rounded to 0 decimals - refund_amount_eur - sum of order_returns.refund_total converted to EUR for returns tied to that month's orders, rounded to 0 decimals - gmv_eur - sum of orders.subtotal converted to EUR for that month's orders, rounded to 0 decimals - net_leakage_pct - (discount_given_eur + refund_amount_eur) / gmv_eur * 100, rounded to 1 decimal Details: Source: orders (placed_at in 2025, all tenants) left joined to order_returns on order_id for refund_total (attributed to the month of the original order, not the return date, so leakage is tied to the order cohort). Same EUR conversion approach as the other two reports tonight (exchange_rates, as_of the relevant date, EUR=rate 1). Cover all 12 months of 2025 even if a month has no qualifying rows. Order by month ascending. Check your query with the warehouse's dry_run tool, then hand it in with submit.
dry_runWITH order_agg AS ( SELECT TO_CHAR(o.placed_at, 'YYYY-MM') AS month, COUNT(*) AS orders_count, SUM(o.discount_total * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS discount_eur, SUM(o.subtotal * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), refund_agg AS ( SELECT TO_CHAR(o.placed_at, 'YYYY-MM') AS month, SUM(ret.refund_total * CASE WHEN ret.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025 ) SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, ROUND(COALESCE(oa.discount_eur, 0), 0) AS discount_given_eur, ROUND(COALESCE(ra.refund_eur, 0), 0) AS refund_amount_eur, ROUND(COALESCE(oa.gmv_eur, 0), 0) AS gmv_eur, ROUND( CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END, 1) AS net_leakage_pct FROM months m LEFT JOIN order_agg oa ON oa.month = m.month_label LEFT JOIN refund_agg ra ON ra.month = m.month_label ORDER BY m.month_label
STATUS: REJECTED - does not compile: Catalog Error: Scalar Function with name to_char does not exist!
dry_runWITH order_agg AS ( SELECT strftime(o.placed_at, '%Y-%m') AS month, COUNT(*) AS orders_count, SUM(o.discount_total * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS discount_eur, SUM(o.subtotal * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), refund_agg AS ( SELECT strftime(o.placed_at, '%Y-%m') AS month, SUM(ret.refund_total * CASE WHEN ret.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025 ) SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, ROUND(COALESCE(oa.discount_eur, 0), 0) AS discount_given_eur, ROUND(COALESCE(ra.refund_eur, 0), 0) AS refund_amount_eur, ROUND(COALESCE(oa.gmv_eur, 0), 0) AS gmv_eur, ROUND( CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END, 1) AS net_leakage_pct FROM months m LEFT JOIN order_agg oa ON oa.month = m.month_label LEFT JOIN refund_agg ra ON ra.month = m.month_label ORDER BY m.month_label
STATUS: COMPILES (dry run on the empty schema, no data read) COLUMNS: month, orders_count, discount_given_eur, refund_amount_eur, gmv_eur, net_leakage_pct
submitWITH order_agg AS ( SELECT strftime(o.placed_at, '%Y-%m') AS month, COUNT(*) AS orders_count, SUM(o.discount_total * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS discount_eur, SUM(o.subtotal * CASE WHEN o.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS gmv_eur FROM orders o LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = o.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), refund_agg AS ( SELECT strftime(o.placed_at, '%Y-%m') AS month, SUM(ret.refund_total * CASE WHEN ret.currency_code = 'EUR' THEN 1 ELSE 1.0 / er.rate END) AS refund_eur FROM order_returns ret JOIN orders o ON o.id = ret.order_id LEFT JOIN exchange_rates er ON er.base_code = 'EUR' AND er.quote_code = ret.currency_code AND er.as_of = CAST(o.placed_at AS date) WHERE o.placed_at >= DATE '2025-01-01' AND o.placed_at < DATE '2026-01-01' GROUP BY 1 ), months AS ( SELECT DISTINCT month_label FROM calendar_days WHERE year_num = 2025 ) SELECT m.month_label AS month, COALESCE(oa.orders_count, 0) AS orders_count, ROUND(COALESCE(oa.discount_eur, 0), 0) AS discount_given_eur, ROUND(COALESCE(ra.refund_eur, 0), 0) AS refund_amount_eur, ROUND(COALESCE(oa.gmv_eur, 0), 0) AS gmv_eur, ROUND( CASE WHEN COALESCE(oa.gmv_eur, 0) = 0 THEN NULL ELSE (COALESCE(oa.discount_eur, 0) + COALESCE(ra.refund_eur, 0)) / oa.gmv_eur * 100 END, 1) AS net_leakage_pct FROM months m LEFT JOIN order_agg oa ON oa.month = m.month_label LEFT JOIN refund_agg ra ON ra.month = m.month_label ORDER BY m.month_label
Submitted to tonight's batch. Your work on this request is done.