Write a SQL query to calculate the rolling 30-day sales volume for each product in our inventory.
Use the inventory products and sales records. Calculate sales by product and sales date, then determine the volume for the current date and the preceding 29 calendar days. Include only sales associated with products in the inventory.
product_id, product_name, sales_date, daily_sales_volume, and rolling_30_day_sales_volume.product_id, then sales_date ascending.| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique inventory product identifier |
| product_name | VARCHAR(100) | Product name |
| sku | VARCHAR(40) | Stock keeping unit |
| category | VARCHAR(60) | Product category |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sales record identifier |
| product_id | INT | Referenced inventory product identifier |
| sale_date | DATE | Calendar date of the sale |
| quantity | INT | Units sold in the record |