A retail company needs to analyze sales data to determine total sales per product category. The existing SQL query is slow and needs optimization. Write a SQL query that efficiently calculates the total sales for each product category by joining the sales and products tables.
sales table with the products table on product_idcategorysales (id, product_id, amount, sale_date)
| id | product_id | amount | sale_date |
|---|---|---|---|
| 1 | 101 | 200 | 2024-01-01 |
| 2 | 102 | 150 | 2024-01-02 |
| 3 | 101 | 300 | 2024-01-03 |
| 4 | 103 | 400 | 2024-01-01 |
products (id, name, category)
| id | name | category |
|---|---|---|
| 101 | Laptop | Electronics |
| 102 | Headphones | Electronics |
| 103 | Shirt | Clothing |
| category | total_sales |
|---|---|
| Electronics | 450 |
| Clothing | 400 |