BASF wants to monitor daily sales trends for products tracked in its commercial sales system. Write a PostgreSQL query that calculates a rolling 7-day average of completed sales for each product.
product_name, sale_date, daily_sales, and rolling_7_day_avg, in that order.product_name ascending, then sale_date ascending.rolling_7_day_avg to two decimal places.NULL sale amounts as numeric zero.| Column | Type | Description |
|---|---|---|
| product_idPK | INTEGER | Unique product identifier |
| product_name | VARCHAR(100) | BASF product name |
| business_unit | VARCHAR(100) | Product business unit |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INTEGER | Unique sales transaction identifier |
| product_id | INTEGER | References products.product_id |
| sale_date | DATE | Date of the transaction |
| sale_amount | NUMERIC(12,2) | Transaction sales value |
| status | VARCHAR(20) | Transaction status |