I have a table that holds this information:
purchase_id (int primary key)
product_purchased (varchar, its the products name)
purchase_date (date)
quantity (int)
customer_id (int)
What i am interested in is my top selling product (product_purchased). Basically in psuedo code i want to do this
select all from table, add up all quantity for each distinct product_purchased print out each product_purcased with the total quantity in order of quantity DESC
if i have these records
1, hat, 2002-01-01, 3, 89
2, scarf, 2002-01-01, 1, 102
3, pants, 2002-01-01, 5, 67
4, scarf, 2002-01-01, 3, 45
5, pants, 2002-01-01, 2, 32
6, hat, 2002-01-01, 7, 98
the results i want are:
hat 10 (total of 10 hats have been purchased)
pants 7 (total of 7 pants have been purchased)
scarf 4 (total of 4 scarfs have been purchased)
Thanks, im wracking my brain out trying to figure out how to write this in a SQL statement!