Your question is Window Functions Running Total. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Samba TV's measurement team wants to monitor cumulative sales associated with active advertising campaigns. Write a PostgreSQL query that aggregates sales by campaign and date, then calculates a chronological running total for each active campaign.
active.sales_amount by campaign and sale_date, treating missing or null sales amounts as zero.| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Unique campaign identifier |
| campaign_name | VARCHAR(100) | Samba TV campaign name |
| status | VARCHAR(20) | Campaign lifecycle status |
| advertiser | VARCHAR(100) | Advertiser associated with the campaign |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sales record identifier |
| campaign_id | INT | Referenced campaign identifier |
| sale_date | DATE | Date on which the sale was attributed |
| sales_amount | NUMERIC(12,2) | Attributed sales amount |
| source | VARCHAR(30) | Attribution source |