Walmart Labs wants category-level sales trends for Walmart's digital commerce reporting. Write a PostgreSQL query that calculates a seven-day rolling average of daily sales for each product category.
The rolling window must cover the current date and the six preceding calendar dates. Dates with no sales must count as zero, and categories with products but no sales during the period must still appear.
2024-01-01 through 2024-01-07 and fill missing sales with zero.| Column | Type | Description |
|---|---|---|
| product_idPK | INTEGER | Unique product identifier |
| product_name | VARCHAR(100) | Product display name |
| category | VARCHAR(50) | Product category |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INTEGER | Unique sale identifier |
| product_id | INTEGER | Product sold |
| sale_date | DATE | Date on which the sale occurred |
| sales_amount | NUMERIC(12,2) | Monetary value of the sale |