The table records credit card transactions where each row is one record.
The columns are: transaction_id, customerID, dollar_spent, product_category.
How can I pick up the 3 customerID's from each product_category that have the highest dollar_spent within that category?
I was thinking about something like:
select product_category, customerID, sum(dollar_spent)
from transaction
group by product_category, customerID
order by sum(dollar_spent) desc limit 3
but it failed to pass. Removing "limit 3" helped it to pass but the whole result is sorted solely by sum(dollar_spent), not by sum(dollar_spent) within each product_category.
Searched on StackOverflow but didn't find anything relevant. Could someone help me with this? Many thanks!!