NovaCart launched a new product on a known launch date and wants to compare product performance immediately before and after launch. Write a SQL query to measure pre-launch vs post-launch performance for each launched product.
Requirements
- For each launched product, compare the 30 days before launch with the 30 days after launch.
- Return these columns:
product_id, product_name, launch_date, pre_orders, post_orders, pre_revenue, post_revenue, revenue_change_pct.
- Only include products where
launch_date is not null.
- Sort by
revenue_change_pct descending, then product_id ascending.
Table Definitions
products
| column | type | description |
|---|
| product_id | INT | Product identifier |
| product_name | VARCHAR(100) | Product name |
| category | VARCHAR(50) | Product category |
| launch_date | DATE | Product launch date |
orders
| column | type | description |
|---|
| order_id | INT | Order identifier |
| customer_id | INT | Customer placing the order |
| order_date | DATE | Order date |
| status | VARCHAR(20) | Order status |
order_items
| column | type | description |
|---|
| order_item_id | INT | Order line identifier |
| order_id | INT | Related order |
| product_id | INT | Purchased product |
| quantity | INT | Units purchased |
| unit_price | DECIMAL(10,2) | Price per unit |