Your question is SQL Window Functions for MoM Growth. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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 |