Analytical SQL for Marketing and Product Funnels
Query funnels, attribution, and cohorts.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
Write SQL for funnels, attribution, and cohorts. Database and dialect: [DATABASE_AND_DIALECT]. Schema (events, sessions, users, orders, campaigns): [SCHEMA]. Funnel steps and definitions: [FUNNEL_STEPS]. Attribution rule (first touch, last touch, or other): [ATTRIBUTION_RULE]. Time range and time zone: [TIME_RANGE]. Model the approach on this example for a three-step funnel. Step flags per user: SELECT user_id, MAX(CASE WHEN event = 'view_product' THEN 1 ELSE 0 END) AS viewed, MAX(CASE WHEN event = 'add_to_cart' THEN 1 ELSE 0 END) AS carted, MAX(CASE WHEN event = 'purchase' THEN 1 ELSE 0 END) AS bought FROM events WHERE event_time >= '2026-09-01' AND event_time < '2026-10-01' GROUP BY user_id; Funnel: SELECT SUM(viewed), SUM(carted), SUM(bought) over those flags; conversion = next step / previous step. Caveat: this counts users who did each step in the period, not necessarily in order; use timestamps for ordered funnels. Provide queries for: an ordered funnel using timestamps, drop-off by step and by channel, first-touch and last-touch attribution on the same orders so I can compare, a campaign performance table (spend, clicks, conversions, cost per conversion) joined safely without double counting, and weekly cohort conversion. Explain each query, list data quality checks (duplicate events, bots, internal traffic, time zones), and give expected result shapes. Avoid claiming causation from attribution.
Fill in before use
Optional: type your details and the prompt above updates. Nothing is saved or sent.
Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.