Loading problem...
An analytics team tracks customer spending transactions in a single table.
Table: Purchases
Primary key:
Task: Build a weekly Friday spending report for November 2023.
For each Friday in November 2023:
Definitions:
Output requirements:
Supported submission environments:
Purchases:
| user_id | purchase_date | amount_spend |
|---------|---------------|--------------|
| 11 | 2023-11-07 | 1126 |
| 15 | 2023-11-30 | 7473 |
| 17 | 2023-11-14 | 2414 |
| 12 | 2023-11-24 | 9692 |
| 8 | 2023-11-03 | 5117 |
| 1 | 2023-11-16 | 5241 |
| 10 | 2023-11-12 | 8266 |
| 13 | 2023-11-24 | 12000 |[
{"week_of_month":1,"purchase_date":"2023-11-03","total_amount":5117},
{"week_of_month":4,"purchase_date":"2023-11-24","total_amount":21692}
]Only 2023-11-03 and 2023-11-24 are Fridays with transactions. The two rows on 2023-11-24 are aggregated.
Purchases:
| user_id | purchase_date | amount_spend |
|---------|---------------|--------------|
| 2 | 2023-11-03 | 100 |
| 3 | 2023-11-10 | 350 |
| 4 | 2023-11-17 | 900 |
| 5 | 2023-11-24 | 50 |[
{"week_of_month":1,"purchase_date":"2023-11-03","total_amount":100},
{"week_of_month":2,"purchase_date":"2023-11-10","total_amount":350},
{"week_of_month":3,"purchase_date":"2023-11-17","total_amount":900},
{"week_of_month":4,"purchase_date":"2023-11-24","total_amount":50}
]Each Friday appears once, so each total is the single row value for that date.
Purchases:
| user_id | purchase_date | amount_spend |
|---------|---------------|--------------|
| 7 | 2023-11-06 | 120 |
| 9 | 2023-11-11 | 450 |
| 10 | 2023-11-15 | 300 |[]No Friday rows are present, so no report rows are returned.
Constraints