Grain check for a user by day purchase model
The task
An analytics model fct_user_day is meant to have one row per user per calendar day (UTC), built from purchases. Before building it, check the grain: find every user and day that has more than one purchase.
Return user_id, day (the date of purchased_at), purchases (how many purchases that user made that day) and total_amount (the sum of amount). Only keys with at least two purchases are listed. Sort by user_id, then day.
Expected output
user_iddaypurchasestotal_amount- Sorted by user_id ascending, then day 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
- Campaign by day fact table with cumulative spendhard
- A small data quality test suite as one queryeasy
- Active accounts and seats per day from subscription datesmedium
- Agent by month fact table of tickets created and resolvedmedium
- Current gold customers by region from type 2 historyeasy
- Customer tier at a point in time from type 2 historymedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL