




A retail company needs to analyze its sales performance. Write a SQL query to calculate the month-over-month sales growth for each product category.
sales and products tables by product_id.sales (id, product_id, sale_date, amount)
products (id, category)
| id | product_id | sale_date | amount |
|---|---|---|---|
| 1 | 1 | 2024-01-15 | 200 |
| 2 | 2 | 2024-01-20 | 150 |
| 3 | 1 | 2024-02-10 | 300 |
| 4 | 2 | 2024-02-15 | 200 |
| 5 | 3 | 2024-02-20 | 250 |
| id | category |
|---|---|
| 1 | Electronics |
| 2 | Clothing |
| 3 | Accessories |
| category | month | total_sales | previous_month_sales | growth_percentage |
|---|---|---|---|---|
| Electronics | 2024-01 | 200 | NULL | NULL |
| Electronics | 2024-02 | 300 | 200 | 50.00 |
| Clothing | 2024-01 | 150 | NULL | NULL |
| Clothing | 2024-02 | 200 | 150 | 33.33 |
| Accessories | 2024-02 | 250 | NULL | NULL |
| Column | Type | Description |
|---|---|---|
| idPK | INT | Primary key |
| product_id | INT | Foreign key referencing products |
| sale_date | DATE | Date of the sale |
| amount | DECIMAL | Sale amount |
| Column | Type | Description |
|---|---|---|
| idPK | INT | Primary key |
| category | VARCHAR(255) | Product category |
{"sales":[[1,1,"2024-01-15",200],[2,2,"2024-01-20",150],[3,1,"2024-02-10",300],[4,2,"2024-02-15",200],[5,3,"2024-02-20",250]],"products":[[1,"Electronics"],[2,"Clothing"],[3,"Accessories"]]}Output[["Accessories","2024-02","250","null","null"],["Clothing","2024-01","150","null","null"],["Clothing","2024-02","200","150","33.33"],["Electronics","2024-01","200","null","null"],["Electronics","2024-02","300","200","50.00"]]