Performance marketing wants cost per signup by campaign, but only for campaigns that actually spent money.
Using a CTE, aggregate campaign_spend to one row per campaign_name (total spend and total signups), then return campaign_name, total_spend, total_signups and cost_per_signup (total spend divided by total signups, rounded to 2 decimals) for campaigns whose total spend is above 50000. Skip campaigns with zero signups.
Sample data
More CTEs questions
Practising alone only goes so far — our live cohorts pair SQL depth with dashboards, agentic analytics projects and mock interviews.
Explore the program