Your question is Monthly Sales Trends by Category. 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.
NovaCart wants a monthly sales report by product category. Write a SQL query to calculate total sales per category for each month and show the month-over-month change within each category.
sales to products using product_id.amount is NULL.category and month formatted as YYYY-MM.category, month, total_sales, and sales_trend.sales_trend should be the current month's total minus the previous month's total in the same category. For the first month in a category, return NULL.category, then month.| Column | Type | Description |
|---|---|---|
| idPK | INT | Primary key for sales records |
| product_id | INT | Foreign key referencing products |
| sale_date | DATE | Date of the sale |
| amount | DECIMAL(10,2) | Sale amount |
| Column | Type | Description |
|---|---|---|
| idPK | INT | Primary key for product records |
| category | VARCHAR(255) | Category of the product |
| name | VARCHAR(255) | Name of the product |