Home > Software design >  Output the total amount spent by the customer and the item on which he/she spent the most
Output the total amount spent by the customer and the item on which he/she spent the most

Time:01-24

There is a table like this, how can I get customer_id, amount_spent, top_item out of it?

amount_spent the amount spent on all items by this customer

top_item, which displays the name of the item for which the customer has spent the most money

Table

I have tried the following query, however I cannot output the top_1 item with it


select customer_id, sum(item_number * item_price) as amount_spent_1m 
from temp
group by customer_id

Check the demo enter image description here

  • Related