Write a SQL query to calculate weekly sales, labor cost, and margin by McDonald's store using window functions or CTEs.
Use the provided McDonald's store, sales, and labor data. Treat weeks as Monday through Sunday and include every store-week with sales or labor activity. Missing sales or labor amounts should be treated as zero.
Output
- One row per store and week, excluding weeks with no activity
- Columns:
store_id, store_name, week_start, weekly_sales, labor_cost, margin, prior_week_margin, and margin_change
- Margin equals weekly sales minus labor cost; week-over-week fields compare rows within each store
- Order by
store_id, then week_start ascending