Spend and sign-ups per campaign from two sources
The task
The marketing report builds one row per campaign from two separate sources: total spend from ad_daily, and the number of sign-ups credited to the campaign in signups (organic sign-ups, with no campaign, are not part of this report).
A campaign must appear if it has spend rows or credited sign-ups, even when the other source has nothing for it. Take the name from campaigns.
Return:
campaign_idcampaign_nametotal_spend: sum ofspend, or 0 if there are no spend rowssignups: number of credited sign-ups, or 0
Sort by campaign_id.
Expected output
campaign_idcampaign_nametotal_spendsignups- Sorted by campaign_id ascending.
- 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
- Daily spend against sign-ups for one campaignhard
- Sign-ups per campaign who placed a large ordereasy
- April spend and cost per click for search and socialeasy
- Completed trips for every city and vehicle typemedium
- Kitchen revenue by customer country, four tablesmedium
- Organic sign-ups during each campaign's runmedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL