Multi-Touch Attribution in SQL with Window Functions
<p>Kora Threads, a Jaipur brand selling hand-block-printed bedsheets online, has to set its Diwali marketing budget, and two dashboards disagree: Google Ads says search drove the summer's sales, the Instagram agency says social did, and together they claim more orders than the store had. Ishita Kulkarni, the marketing analyst, decides to answer from Kora's own orders and touchpoints, with rules everyone can see.</p><p>Across five lessons you build the answer with her, on Kora's data in an in-browser SQL lab: real orders in a half-open period, duplicate pixel fires removed with LAG() over the right partition, conversion journeys joined on a 30-day lookback and the previous real order (with the window computed before the filter), days to convert by calendar date, first- and last-touch models with ROW_NUMBER() (and the LAST_VALUE frame trap), linear and 40/20/40 position-based credit with COUNT(*) OVER and conservation checks, a four-model comparison, ROAS without a join fan-out, and assisted conversions. Every lesson you write the SQL yourself first, then hand the same job to your AI (ChatGPT, Claude, Copilot or Gemini) and learn exactly where it goes wrong. In the capstone your AI writes the budget pack from one brief, and you prove every number before a rupee moves.</p>
Tools: SQL (MySQL), Window functions (LAG, ROW_NUMBER, COUNT OVER), Window frames (LAST_VALUE), CTEs and range joins, Timestamps, DATEDIFF, TIMESTAMPDIFF and DATE_SUB, Marketing attribution models, ROAS and assisted conversions, AI assistants for SQL