Canva’s marketing analytics team wants to identify the best-performing channel for each active campaign during Q1 2026. Write one PostgreSQL query using the campaign, channel, and daily performance tables.
Requirements
- Include only active campaigns launched on or before 2026-03-31, active marketing channels, and performance recorded from 2026-01-01 through 2026-03-31.
- Aggregate spend, impressions, clicks, and conversions by campaign and channel.
- Calculate click-through rate as clicks divided by impressions, expressed as a percentage, and cost per conversion.
- Rank channels within each campaign by conversions descending, then spend ascending, and return only the top-ranked channel for each campaign.
Output details
- Return columns in this order:
campaign_name, channel_name, total_spend, total_impressions, total_clicks, total_conversions, ctr_pct, cost_per_conversion, channel_rank.
- Round
ctr_pct and cost_per_conversion to two decimal places.
- Treat missing spend as
0.00, and return NULL for ctr_pct when impressions are zero or cost_per_conversion when conversions are zero.
- Break ranking ties by
channel_name ascending after conversions descending and spend ascending.
- Sort the final rows by
campaign_name ascending.