Campaign Efficiency Metrics and Below-Average CTR
You are given an ad_campaigns table with one row per campaign:
| Column | Type | Meaning |
|---|
campaign_id | INTEGER | Unique campaign identifier |
campaign_name | VARCHAR | Campaign name |
start_date | DATE | First active date, inclusive |
end_date | DATE | Last active date, inclusive |
daily_budget | DECIMAL | Planned budget per active day |
impressions | INTEGER | Recorded impressions |
clicks | INTEGER | Recorded clicks |
conversions | INTEGER | Recorded conversions |
For this console, use PostgreSQL and the following explicit assumptions: campaign dates are inclusive, each row covers one entire campaign, and daily_budget is constant across its active dates.
Write one query that returns only campaigns whose campaign-level click-through rate is below the arithmetic mean of the valid campaign-level click-through rates.
Return these columns:
-
campaign_id
-
campaign_name
-
total_cost
:
daily_budget
multiplied by the inclusive number of active dates
-
ctr
:
clicks / impressions
-
conversion_rate
:
conversions / clicks
-
cost_per_conversion
:
total_cost / conversions
Use decimal division. When a denominator is zero, return NULL for that rate rather than raising an error. Campaigns with zero impressions do not contribute to the average CTR and cannot be classified as below it. Order the final rows by campaign_id.
After writing the query, be prepared to explain whether daily_budget × active_days represents actual spend or only planned budget.