Campaigns cheaper per sign-up than their channel
The task
Marketing wants to know which campaigns beat the rest of their channel on cost per sign-up.
- A campaign's spend is the sum of
ad_daily.spendfor the campaign. - A campaign's sign-ups are the rows in
signupswhosecampaign_idis that campaign. Organic sign-ups (NULLcampaign_id) belong to no campaign. - A campaign's
cost_per_signupis its spend divided by its sign-ups. - A channel's
channel_cost_per_signupis the total spend of all its campaigns divided by the total sign-ups of all its campaigns. A campaign with spend and no sign-ups adds its spend to the channel total, and adds nothing to the sign-ups.
Return the campaigns that have at least one sign-up and whose cost_per_signup is strictly lower than their channel's. Give campaign_id, channel, cost_per_signup and channel_cost_per_signup, both rounded to 2 decimal places, sorted by campaign_id.
Expected output
campaign_idchannelcost_per_signupchannel_cost_per_signup- Sorted by campaign_id ascending.
- Numbers rounded to 2 decimal places.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables Marketing team · click a name to insert it
campaigns10 rows in the sample
One row per campaign. Key: campaign_id.
| int | Unique id. | |
| text | Name. | |
| text | search, social, video, email or affiliate. | |
| date | First day live. | |
| date | Last day live. NULL if still running. | |
| numeric(10,2) | Budget per day, USD. |
ad_daily969 rows in the sample
One row per campaign per day it served ads. Days with no delivery have no row. Key: campaign_id, day.
| int | The campaign. | |
| date | The day. | |
| int | Times an ad was shown. | |
| int | Clicks. | |
| numeric(10,2) | Money spent, USD. |
signups2,108 rows in the sample
One row per new user. campaign_id is the campaign credited with the sign-up. Key: user_id.
| int | Unique id. | |
| timestamp | When they signed up (UTC). | |
| int | Credited campaign. NULL for organic sign-ups. | |
| text | Two-letter country code. |
purchases2,294 rows in the sample
One row per paid order by a user. Key: purchase_id.
| int | Unique id. | |
| int | Buyer. | |
| timestamp | When (UTC). | |
| numeric(10,2) | Order value, USD. |
Related questions
- Agent share of their team's ticketseasy
- Average transactions per open accountmedium
- Listeners whose first play was on a speakermedium
- Ticket categories with an above-average urgent sharemedium
- Ad funnel from impressions to buyers by channelmedium
- Buyers whose latest purchase beat their earlier averagehard
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL