Sales and Product tables on product_id to get the total amount spent on each product per user.SUM() function to calculate the total amount spent by each user on each product.DENSE_RANK() window function to rank the products for each user based on the total amount spent in descending order.user_id and product_id of these top-ranked products.erDiagram
Sales ||--o{ Product : has
Sales {
int sale_id PK
int product_id FK
int user_id
int quantity
}
Product {
int product_id PK
int price
}