How would you use SQL window functions to calculate rolling 7-day sales trends by product and region for W.W. Grainger?
Write a PostgreSQL query using the provided sales, products, and regions data. Include dates with sales activity, calculate daily sales, and calculate the total for the current date plus the preceding six calendar days.
Output
- One row per product, region, and sales date with activity.
- Columns:
product_name, region_name, sales_date, daily_sales, and rolling_7_day_sales.
- Sort by
product_name, region_name, and sales_date ascending.