TechMart tracks all sales in a single sales table. The analytics team needs a dashboard that shows, for each month, the total sales amount for each product category as separate columns.
Write a SQL query to pivot the sales data so that each row represents a month (in YYYY-MM format), and each column shows the total sales for a specific category. Only include sales from January to March 2024 (inclusive).
YYYY-MM.NULL for that column.sales
| Column | Type | Description |
|---|---|---|
| id | INT | Primary key for the sales record |
| category | VARCHAR(255) | Product category for the sale |
| sale_date | DATE | Date of the sale |
| amount | DECIMAL(10,2) | Amount of the sale |
| id | category | sale_date | amount |
|---|---|---|---|
| 1 | Electronics | 2024-01-15 | 200 |
| 2 | Clothing | 2024-01-20 | 150 |
| 3 | Electronics | 2024-02-10 | 300 |
| 4 | Books | 2024-02-15 | 100 |
| 5 | Clothing | 2024-02-25 | 250 |
| 6 | Electronics | 2024-03-05 | 400 |
| 7 | Books | 2024-03-10 | 200 |
| 8 | Clothing | 2024-03-15 | 300 |
| 9 | Electronics | 2023-12-31 | 500 |
| 10 | Books | 2024-01-10 | NULL |
| 11 | Clothing | 2024-02-01 | 0 |
| 12 | Electronics | 2024-03-31 | 0 |
| month | Electronics | Clothing | Books |
|---|---|---|---|
| 2024-01 | 200 | 150 | NULL |
| 2024-02 | 300 | 250 | 100 |
| 2024-03 | 400 | 300 | 200 |