QQUERYDESK/ analytics-report-generator
warehouse analytics_prod · mysql-8.0
rows scanned 0
engine 0.00 ms
--:--:--
mysql> analytics_prod · session — 4 report queries · 5 result sets · deterministic seed
Multi-table joins · window-safe aggregations

Marketing &
Conversion
Report Generator4 queries · 3 joins · 1 fan-out guard

A runnable report desk built on marketing_campaigns ⟕ website_visitors ⟕ conversions. Every metric is computed by an executed aggregation — no hard-coded numbers. Date-window, attribution model and source filters re-execute all four queries and every chart, KPI and export below.

Date range
→ Attribution
rows —exec —idle
01

Marketing ROI by Campaign Flight

marketing_campaigns ⟕ website_visitors ⟕ conversions · GROUP BY mc.campaign_id

roi_by_campaign.sql

Campaign comparison

02

Funnel Conversion Rates by Source

website_visitors ⟕ conversions · CASE WHEN pivot · GROUP BY source

funnel_by_source.sql

Conversion funnel — all sources

session ladder stage (website_visitors.stage) purchase · conversions click a source chip to re-scope the funnel

03

Cohort Performance & Retention Heat Map

DATE_FORMAT(session_start,'%Y-%m') · COUNT(DISTINCT …) · Q3b self-join on visitor_id

cohort_analysis.sql

Retention matrix — first-session cohort × month offset

04

Customer Lifetime Value by Acquisition Source

INNER JOIN conversions ON conversion_type = 'purchase' · GROUP BY wv.source

clv_by_source.sql

AOV → lifetime value spread

avg order value · AVG(c.value) lifetime value per customer repeat multiplier

Methodology, join semantics & caveats

The dataset is generated once from a fixed PRNG seed, then every number on this page is produced by the aggregations shown above. Re-running with a different date window re-executes all five result sets.

Join grain

website_visitors holds one row per session, so visitor_id repeats. Every COUNT(DISTINCT visitor_id) is therefore meaningful and SUM(c.value) over a raw join is not — conversions are pre-aggregated to visitor grain before the campaign join.

Fan-out guard

A visitor with n in-window sessions would join each conversion n times. Revenue is computed over distinct conversion_id; the inflated literal figure is reported in each module's caveat strip so the difference is auditable.

Attribution

Date window (as specified): any visitor with a session inside BETWEEN start_date AND end_date. Strict UTM adds AND wv.utm_campaign = mc.campaign_id. The ROI inflation factor between the two is displayed live.

Spend accrual

budget_spent accrues linearly across the flight; a selected window is charged budget × overlap_days / flight_days. Full-flight budget appears in tooltips.

Revenue sign

conversions.value is signed: refund rows carry negative value and reduce net revenue (Q1/KPIs). Q4 filters conversion_type='purchase', so its AOV is gross of refunds.

Time & performance

All timestamps are local, truncated to session start. Queries run against pre-built hash indexes (byDay, byVisitor, convByVisitor) — typical full-suite execution is well under 20 ms for ~14k joined rows.

QUERYDESK v2.4SEED 20240617—— CSV · JSON · PDF (print)