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.category, sale_date, daily_sales, rolling_7_day_avg.category ascending, then sale_date ascending.rolling_7_day_avg to exactly two decimal places.2024-01-01 and 2024-01-07 as inclusive.0.00.| 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 |