Interview Guides

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.sales| column | type | description |
|---|---|---|
| id | INT | Primary key for each sale |
| product_id | INT | Product sold |
| sale_date | DATE | Date of the sale |
| amount | DECIMAL(10,2) | Sale amount; may be NULL |
products| column | type | description |
|---|---|---|
| id | INT | Primary key for each product |
| category | VARCHAR(255) | Product category |
| name | VARCHAR(255) | Product name |