Write a SQL query to analyze daily sales, shrink, and inventory by department and identify the top underperforming stores using joins and aggregations.
For this exercise, analyze active stores from January 1 through January 3, 2025, and define underperformance by lowest shrink-adjusted sales, calculated as sales minus shrink. Return the three lowest-performing stores.
Output
- One row per included store, department, and date.
- Columns:
store_id, store_name, department_name, metric_date, daily_sales, daily_shrink, ending_inventory, store_performance_score, and underperforming_store_rank.
- Include only the three lowest-performing active stores, ordered by rank, store ID, date, and department name.