How do you optimize SQL queries for performance in a warehouse environment?
Treat this as a hands-on SQL exercise. Using the provided warehouse tables, write an efficient query that preserves correctness while calculating monthly revenue metrics and comparisons.
month_start, region, category, revenue, order_count, prior_month_revenue, revenue_change_pct, and monthly_revenue_rank.month_start, revenue descending, region, and category.| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sale identifier |
| sale_date | DATE | Date of the sale |
| customer_id | INT | Purchasing customer |
| product_id | INT | Purchased product |
| quantity | INT | Units purchased |
| net_amount | DECIMAL(12,2) | Net sale amount |
| status | VARCHAR(20) | Sale processing status |
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Customer identifier |
| region | VARCHAR(30) | Customer sales region |
| segment | VARCHAR(30) | Customer segment |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Product identifier |
| product_name | VARCHAR(80) | Product name |
| category | VARCHAR(30) | Product category |
| Column | Type | Description |
|---|---|---|
| date_keyPK | DATE | Calendar date |
| month_start | DATE | First day of the calendar month |
| is_business_day | BOOLEAN | Whether the date is a business day |