McDonald's Global Office in India wants to identify which menu item is accelerating fastest within each product category. The analysis should compare monthly sales totals for each item.
Write a PostgreSQL query using window functions to return the item with the highest month-over-month sales growth in each category.
products with sales and aggregate sales by item and calendar month.LAG to retrieve the previous available month's sales for each item.| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique menu item identifier |
| item_name | VARCHAR(100) | Menu item name |
| category | VARCHAR(50) | Menu item category |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sales record identifier |
| product_id | INT | Menu item referenced by the sale |
| sale_date | DATE | Date on which the sale occurred |
| sales_amount | DECIMAL(12,2) | Sales value for the record |