Walmart wants to understand customer loyalty toward specific products. Write an SQL query that finds, for each user, the product_id that they spent the most money on.
Total spending for a product is calculated as the sum of (unit_price * quantity) across all sales of that product for that user.
| sale_id(INTEGER) | product_id(INTEGER) | user_id(INTEGER) | quantity(INTEGER) |
|---|---|---|---|
| 1 | 10 | 1 | 2 |
| 2 | 20 | 1 | 1 |
| 3 | 10 | 2 | 5 |
| 4 | 30 | 2 | 1 |
| product_id(INTEGER) | price(INTEGER) |
|---|---|
| 10 | 100 |
| 20 | 500 |
| 30 | 1000 |
| store_id(INTEGER) | city(VARCHAR) |
|---|---|
| 501 | Bentonville |
| 502 | Dallas |
| user_id(INTEGER) | product_id(INTEGER) |
|---|---|
| 1 | 20 |
| 2 | 30 |