Your question is SQL Month-over-Month Revenue Comparison. 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.
Write a SQL query to compare current month revenue with the previous month for each product.
Use the latest month present in sales as the current month. Revenue is calculated as quantity * unit_price; products without sales in either comparison month must still appear.
product_id ascending.product_id, product_name, current_month, previous_month, current_month_revenue, previous_month_revenue, revenue_change, and revenue_change_pct.| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(100) | Product name |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sale identifier |
| product_id | INT | Product sold |
| sale_date | DATE | Date of sale |
| quantity | INT | Units sold |
| unit_price | NUMERIC(10,2) | Price per unit |